twitter api从本地主机上运行,但不能从远程主机运行
问题描述:
在远程主机上运行以下代码时,请继续收到failed to open stream
。twitter api从本地主机上运行,但不能从远程主机运行
$feed = simplexml_load_string(file_get_contents('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=kratteteast&count=1'), 'SimpleXMLElement', LIBXML_NOCDATA);
从localhost
它每次都有效。
任何想法?
编辑:它适用于2种其他饲料(新闻(谷歌)和博客)访问相同的方式。
答
Twitter默认支持localhost。在localhost之外,在twitter api中,您必须将域设置为您使用该窗口小部件的域。
例如,我这样做:
* .stewardxpress.com,* .ihnbc.com
你可以包括由逗号分隔的多个领域。当您在这些域上使用小部件时,Twitter会识别它。除此之外,它只会识别localhost。
我希望这可以帮助你。
编辑
我从我的结尾跑过你的脚本。
$feed = simplexml_load_string(file_get_contents('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=kratteteast&count=1'), 'SimpleXMLElement', LIBXML_NOCDATA);
print_r ($feed) ;
它返回:
SimpleXMLElement Object ([@attributes] => Array ([version] => 2.0) [channel] => SimpleXMLElement Object ([title] => Twitter/KrattetEast [link] => http://twitter.com/KrattetEast [description] => Twitter updates from Tornekrattet Øst/KrattetEast. [language] => en-us [ttl] => 40 [item] => SimpleXMLElement Object ([title] => KrattetEast: @Erlendnr Kanskje her: http://t.co/mZ05VHkIxz [description] => KrattetEast: @Erlendnr Kanskje her: http://t.co/mZ05VHkIxz [pubDate] => Wed, 27 Feb 2013 14:51:08 +0000 [guid] => http://twitter.com/KrattetEast/statuses/306778498259902464 [link] => http://twitter.com/KrattetEast/statuses/306778498259902464)))
检查你的PHP安装和配置。查看您的远程服务器是否以任何方式阻止了跨域访问,或者相同的Twitter限制正在发挥作用。我从localhost测试。
当我测试远程时,我失败了。这就是为什么:
file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0
你可以看到在服务器中禁用了http://封装。所以你有一个服务器问题。修正这与服务器主机。联系管理员。或者你的主要选项是cURL。
确定DOMXML安装在服务器上? – 2013-02-26 15:31:00
['cURL'](http://www.php.net/curl)是否工作? – h2ooooooo 2013-02-26 15:38:14
卷曲确实有效。任何想法为什么file_get_contents不会? – mistenkt 2013-02-26 15:44:20