PHP   发布时间:2019-11-08  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php – 为什么这个Twitter API脚本失败了?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我从这个Twitter脚本收到一个错误,导致页面的其余部分无法加载.不知道为什么突然发生这种情况,它在相当长的一段时间内正常运作.

脚本如下所示,它会提取用户当前状态:

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

这是另一篇文章,我试图找出另一个错误的答案,这个错误指出了我的Twitter错误.

你可以在页脚中看到它here,或者输出的屏幕抓图:http://cl.ly/33IZ.

解决方法

相关错误(显示在您链接到的页面的页脚中)是:
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....',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错误请求”.

因此,出于某种原因,在向Twitter发送http请求以检索文档“http://twitter.com/users/show/tuscaroratackle.xml”时,您的服务器失败了.返回码为400 Bad request.

我刚刚从我的网络浏览器尝试了同样的请求,它工作正常,所以要么Twitter暂时“外出吃午饭”(这确实会不时发生),或者服务器的网络配置有一些独特之处.我的第一个猜测是,从您的服务器上游的某个地方,有人安装了一个http代理(由于某种未知的原因)阻止您的请求.

这是什么twitter has to say about it

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.

Here is twitter’s page on Rate Limiting.我怀疑这是你的罪魁祸首.如果您不这么认为,那么您可能会尝试将文档作为字符串检索并在尝试解析之前对其进行检查,以便您可以看到该消息是什么.

这很快,很脏,但它会收到消息,以便您可以看到正在发生的事情:

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

由于400响应代码可能会失败.如果是这样,你需要使用php curl来获取未解析的响应体.

祝你好运!

大佬总结

以上是大佬教程为你收集整理的php – 为什么这个Twitter API脚本失败了?全部内容,希望文章能够帮你解决php – 为什么这个Twitter API脚本失败了?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。