Twitter API-406不可接受的响应 [英] Twitter API - 406 Not Acceptable Response

查看:96
本文介绍了Twitter API-406不可接受的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于用户个人资料,我通过以下方式查询Twitter搜索API:

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")."");

过去几周效果很好.

几天以来,Twitter API从我的网站收到了很多请求,有时还会回复"406不可接受"

Since a few days the Twitter API gets a lot of requests from my site and sometimes responses with a "406 Not Acceptable"

完整的错误消息是:

array(18){[0] =>字符串(27)"HTTP/1.1 406不可接受" [1] =>字符串(35)日期:2011年1月21日星期五12:31:06 GMT" [ 2] =>字符串(10)服务器:高" [3] =>字符串(26)状态:406不可接受" [4] =>字符串(15)重试后: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)缓存控制:max-age = 15,必须重新验证,max-age = 300"[9] => string(38)"到期时间:2011年1月21日,星期五,格林尼治标准时间"[10] => string(21)" Vary:Accept-Encoding"[11] => string( 17)内容长度:1" [12] =>字符串(21)"X-清漆:1897557299" [13] =>字符串(6)年龄:0" [14] =>字符串(16)通过:1.1清漆"[15] =>字符串(45)" X-Cache-Svr:slc1-acm-32-sr1.prod.twitter.com"[16] =>字符串(13)" X-Cache:MISS"[17] =>字符串(17)"Connection:close"}

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" }

我不了解Twitter Doku:

I don't understand the Twitter Doku about this:

http://apiwiki.twitter.com/w/page/22554652/HTTP-Response-Codes-and-Errors 说"406不可接受:当请求中指定了无效格式时,由Search API返回."

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)原子

1) json
2) atom

您正在使用rss.这就是为什么您会收到错误消息.必须将格式指定为扩展名.像这样:

And you're using rss. That's why you're getting the error. The format has to be specified as the extension. Like this:

http://search.twitter.com/search.format


解决方案:
使用atom或json格式,如下所示:


Solution:
Use atom or json format, like this:

http://search.twitter.com/search.json?q=twitter

完整代码应如下所示:

curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.json?q=".urlencode($username."+-badword")."");

这篇关于Twitter API-406不可接受的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆