Getting an 401 error with any POST request to twitter REST API

oauth
api

#1

I’m having trouble with post requests to the Twitter REST API. All GET requests seem to work fine, but POST requests return this:

401 Authorization Required response:
{“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}

I’m using Laravel 5.3, Guzzle 6.3 and Guzzle/oauth-subscriber 0.3. Here’s my code:

$stack = HandlerStack::create();

$middleware = new Oauth1([
    'consumer_key'    => env('TWITTER_CLIENT_ID'),
    'consumer_secret' => env('TWITTER_CLIENT_SECRET'),
    'token'           => env('TWITTER_TOKEN'),
    'token_secret'    => env('TWITTER_TOKEN_SECRET')
]);

$stack->push($middleware);

$client = new Client([
    'base_uri' => 'https://api.twitter.com/1.1/',
    'handler' => $stack
]);

$res = $client->post(
  'account/update_profile_image.json?image=' . $avatar,
  [
    'auth' => 'oauth',
  ]
);