2013-02-26 122 views
0

在远程主机上运行以下代码时,请继续收到failed to open streamtwitter 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种其他饲料(新闻(谷歌)和博客)访问相同的方式。

+0

确定DOMXML安装在服务器上? – 2013-02-26 15:31:00

+0

['cURL'](http://www.php.net/curl)是否工作? – h2ooooooo 2013-02-26 15:38:14

+0

卷曲确实有效。任何想法为什么file_get_contents不会? – mistenkt 2013-02-26 15:44:20

回答

0

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。

+0

他没有使用小部件;他正在做一个服务器端API调用 – SLaks 2013-02-26 16:43:25

+0

对不起,我的不好!我知道Twitter现在有域限制。我可能有时间看看服务器端API – 2013-02-26 17:02:03

+0

感谢评论家伙,只是使用cURL,因为它似乎有伎俩。但是,如果确切知道是什么让file_get_contents失败了,以防万一我稍后碰到类似的问题,那就太好了。 – mistenkt 2013-02-27 15:29:25

相关问题