For a user profile i query the Twitter Search API via:
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.rss?q=".urlencode($username."+-badword")."");
which worked excellent the last weeks.
Since a few days the Twitter API gets a lot of requests from my site and sometimes responses with a “406 Not Acceptable”
the complete error message is:
array(18) { [0]=> string(27) “HTTP/1.1 406 Not Acceptable” [1]=> string(35) “Date: Fri, 21 Jan 2011 12:31:06 GMT” [2]=> string(10) “Server: hi” [3]=> string(26) “Status: 406 Not Acceptable” [4]=> string(15) “Retry-After: 10” [5]=> string(30) “X-Served-From: slc1-aah-25-sr1” [6]=> string(38) “Content-Type: text/html; charset=utf-8” [7]=> string(45) “X-Served-By: slc1-acm-32-sr1.prod.twitter.com” [8]=> string(55) “Cache-Control: max-age=15, must-revalidate, max-age=300” [9]=> string(38) “Expires: Fri, 21 Jan 2011 12:36:06 GMT” [10]=> string(21) “Vary: Accept-Encoding” [11]=> string(17) “Content-Length: 1” [12]=> string(21) “X-Varnish: 1897557299” [13]=> string(6) “Age: 0” [14]=> string(16) “Via: 1.1 varnish” [15]=> string(45) “X-Cache-Svr: slc1-acm-32-sr1.prod.twitter.com” [16]=> string(13) “X-Cache: MISS” [17]=> string(17) “Connection: close” }
I don’t understand the Twitter Doku about this:
http://apiwiki.twitter.com/w/page/22554652/HTTP-Response-Codes-and-Errors says “406 Not Acceptable: Returned by the Search API when an invalid format is specified in the request.”
because, when i retry after a few seconds the request works fine again.
Who has an idea how to fix this?
Reason:
From the docs, the supported formats are:
1) json
2) atom
And you’re using
rss. That’s why you’re getting the error. The format has to be specified as the extension. Like this:Solution:
Use atom or json format, like this:
Full code should look like: