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

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

问题描述

我收到此 Twitter 脚本的错误,导致页面的其余部分无法加载.不知道为什么突然发生这种情况,它在很长一段时间内都可以正常运行.

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 错误.

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.

You can see it here in the footer, or a screengrab of the output: 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".

因此,由于某种原因,您的服务器在向 Twitter 发出 HTTP 请求以检索文档 "http://twitter.com/users/show/tuscaroratackle.xml" 时失败.返回码是400 Bad Request.

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.

我刚刚从我的网络浏览器尝试了相同的请求,它运行良好,所以要么 Twitter 暂时出去吃午饭"(这种情况不时发生),要么您的服务器的网络配置有一些独特之处.我的第一个猜测是,在您的服务器上游某处,有人安装了一个 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 响应代码而失败.如果是这样,您需要使用 php curl 来获取未解析的响应体.

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天全站免登陆