Server environment causing 400 bad request error on api call?


#1

Moving the site from staging server to production server has resulted in the 400 bad request error. It is exactly the same code that works fine on the staging server. The get_headers request returns the following:

Array ( [0] => HTTP/1.0 404 Not Found [1] => X-RateLimit-Limit: 150 [2] => X-RateLimit-Remaining: 132 [3] => X-RateLimit-Reset: 1338576073 [4] => X-RateLimit-Class: api [5] => Last-Modified: Fri, 01 Jun 2012 17:41:32 GMT [6] => Expires: Tue, 31 Mar 1981 05:00:00 GMT [7] => Pragma: no-cache [8] => Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0 [9] => Set-Cookie: guest_id=“v1:133857249231372253”;Expires=Sun, 1-Jun-14 17:41:32 GMT;Path=/;Domain=.twitter.com [10] => Status: 404 Not Found [11] => X-Transaction: b49bb5d201269094 [12] => X-Frame-Options: SAMEORIGIN [13] => Date: Fri, 01 Jun 2012 17:41:32 GMT [14] => Content-Type: application/xml; charset=utf-8 [15] => Content-Length: 116 [16] => Server: tfe [17] => Connection: Keep-Alive )

Clearly the rate limit is not being reached, plus it shows that it is a 404 error. But when I run the script I get this:

Warning: simplexml_load_file(http://api.twitter.com/1/statuses/user_timeline/the_user_name.xml?count=2&trim_user=true&include_rts=true&exclude_replies=true&contributor_details=true) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

showing a 400 error.

Works on staging server but not live site so it must be hosting environment, but what to look for? Curl is enabled, simpleXML is installed.

Any ideas?


#2

We really recommend using a more robust instrument than simplexml_load_file. You will likely also want to leverage OAuth.

There are bodies to the errors we send. The body will contain more information as to why you’ve gotten the error you got. I’m not sure if simplexml_load_file is capable of telling you what those errors are. You’ll need to investigate.

The URL pattern you’re trying to use is also outdated. Consider using http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=the_user-Name and so on instead. 400 errors are a normal part of operations. Understand their meaning and handle them with exception handling.


#3

Thanks Taylor,
that was the full error I posted except for the file reference, which has sensitive server info I wouldn’t make public.

I am using exception handling, but it doesn’t solve the problem. I used the dev api console to try a few different calls. In the end the only one that worked is this:

http://twitter.com/statuses/user_timeline/the_user_name.json?callback=twitterCallback2&count=4

It’s probably deprecated but it works. Maybe the server people can shed some light.


#4