这是为什么Twitter的API脚本失败? [英] Why is this Twitter API script failing?

查看:158
本文介绍了这是为什么Twitter的API脚本失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从导致该页面的其余部分,以无法加载此微博脚本得到一个错误。不知道为什么突然发生这种情况,它被正常运行了相当一段时间。

I'm getting an error from this Twitter script that is causing the rest of the page to not load. Not sure why suddenly this is happening, where it was functioning properly for quite some time.

该脚本看起来像这样,并将其拉用户的当前状态:

The script looks like this, and it pulls the users current status:

<?php  
$response = new SimpleXMLElement('http://twitter.com/users/show/tuscaroratackle.xml',NULL,TRUE);  
echo $response->status->text.'';  
?>

下面是另一篇文章,我试图找出答案这向我指出这个错误Twitter的另一个bug。

Here's another post that I was trying to figure out the answer to another bug which pointed me to this Twitter error.

您可以在这里看到在页脚,或输出的截屏:的 http://cl.ly/33IZ

推荐答案

相关的错误(这是显示在您链接到页面的页脚)是:

The relevant error (which is displayed in the footer of the page you linked to) is:

Warning: SimpleXMLElement::__construct(http://twitter.com/users/show/tuscaroratackle.xml) [simplexmlelement.--construct]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home5/tuscaror/public_html/footer.php on line 47

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: I/O warning : failed to load external entity "http://twitter.com/users/show/tuscaroratackle.xml" in /home5/tuscaror/public_html/footer.php on line 47

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home5/tuscaror/public_html/footer.php:47 Stack trace: #0 /home5/tuscaror/public_html/footer.php(47): SimpleXMLElement->__construct('http://twitter....', 0, true) #1 /home5/tuscaror/public_html/index.php(119): include('/home5/tuscaror...') #2 {main} thrown in /home5/tuscaror/public_html/footer.php on line 47

第一个警告会告诉你发生了什么。!HTTP请求失败,HTTP / 1.1 400错误的请求

The first warning tells you what happened: "HTTP request failed! HTTP/1.1 400 Bad Request".

所以,出于某种原因,你的服务器正在HTTP请求到Twitter要检索文档时失败http://twitter.com/users/show/tuscaroratackle.xml。返回code是 400错误的请求

So, for some reason, your server is failing when making the HTTP request to twitter to retrieve the document "http://twitter.com/users/show/tuscaroratackle.xml". The return code is 400 Bad Request.

我只是想从我的Web浏览器同样的要求,它工作得很好,所以无论是微博暂时外出就餐(这确实发生不时),或者有一些关于你的服务器的网络配置是唯一的。我的第一个猜想是,某处上游从你的服务器,有人已经安装的是(对于一些未知的原因)阻止你的请求的HTTP代理。

I just tried that same request from my web browser, and it worked fine, so either twitter was temporarily "out to lunch" (which does happen from time to time), or there is something unique about your server's network configuration. My first guess would be that somewhere up-stream from your server, someone has installed an HTTP proxy which is (for some unknown reason) blocking your request.

下面就是 Twitter已经说些什么的:

400 Bad Request: The request was invalid.  An accompanying error message 
will explain why. This is the status code will be returned during rate limiting.

这里是Twitter的月率限制页。我怀疑这是您的罪魁祸首。如果你觉得不然,那么你可以尝试检索文档作为一个字符串,并在的研究它的您尝试解析它,所以你可以看到的信息是什么。

Here is twitter's page on Rate Limiting. I suspect that this is your culprit. If you think otherwise, then you might try retrieving the document as a string and examining it before you try to parse it, so you can see what the message is.

这是快速和肮脏的,但它会得到的消息,所以你可以看到发生了什么:

This is quick and dirty, but it'll get the message so you can see what's going on:

$str = file_get_contents('http://twitter.com/users/show/tuscaroratackle.xml');
echo $str;

这可能会由于400响应code。如果是这样,你需要使用 PHP卷曲以获得不解析响应体。

that may fail due to the 400 response code. if so, you'll need to use php curl to get the un-parsed response body.

好运!

这篇关于这是为什么Twitter的API脚本失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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