Empty body in response from the request/token Twitter endpoint



I’m using the abraham/twitteroauth PHP library to do server-side integration with Twitter. The integration works well in my local development server, which means I can make a tweet on behalf of my Twitter app on a user’s timeline. However, once deployed to my staging environment the integration fails at the request/token endpoint. I’m using the Google AppEngine for my staging environment.

I use the following code for the request/token endpoint:

use Abraham\TwitterOAuth\TwitterOAuth;
$callback = 'http://<SOME_CALLBACK_URL>';
$twitter = new TwitterOAuth('<APP_KEY>', '<APP_SECRET>');
$response = $twitter->oauth('oauth/request_token', array('oauth_callback' => $callback));

However, there are no oauth data available in $response. The following parameters should be set:

  • $response[‘oauth_token’]
  • $response[‘oauth_token_secret’]
  • $response[‘oauth_callback_confirmed’]

No exceptions are thrown. No cURL errors are reported. Nothing. The HTTP response is 200.

Any ideas?

The response in plain text:

HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, 
content-encoding: gzip
content-length: 129
content-security-policy: default-src 'none'; connect-src 'self'; 
font-src https://abs.twimg.com https://abs-0.twimg.com data:; frame-src 
'self' twitter:; img-src https://abs.twimg.com https://*.twimg.com 
https://pbs.twimg.com data:; media-src 'none'; object-src 'none'; 
script-src https://abs.twimg.com https://abs-0.twimg.com 
https://twitter.com https://mobile.twitter.com; style-src 
https://abs.twimg.com https://abs-0.twimg.com; report-uri 
date: Fri, 30 Sep 2016 10:10:31 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Fri, 30 Sep 2016 10:10:31 GMT
ml: S
pragma: no-cache
server: tsa_a
set-cookie: guest_id=v1%3A147523023189812803; Domain=.twitter.com; 
Path=/; Expires=Sun, 30-Sep-2018 10:10:31 UTC
status: 200 OK
strict-transport-security: max-age=631138519
x-connection-hash: a0071d129f21fb5da28b27e273640478
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-response-time: 93
x-transaction: 00a30d63001d63c7
x-twitter-response-tags: BouncerCompliant
x-ua-compatible: IE=edge,chrome=1
x-xss-protection: 1; mode=block


Apparently, Google AppEngine’s cURL implementation doesn’t handle gzip very well, which is why I got the “empty” response from Twitter. The following code fixed this issue for me: