【问题标题】:server not retrieving GET statuses/user_timeline information from twitter服务器未从 twitter 检索 GET 状态/user_timeline 信息
【发布时间】:2012-07-01 13:05:06
【问题描述】:

我正在尝试创建一个简单的小部件来检索用户提要,我已将我的应用程序完全设置为使用 twitter API 的 @anywhere 和 OAuth 功能。

我遇到的问题是当我尝试检索用户的推文并将它们再次写入文本文件时。 我这样做的代码如下

    <?php

    $cache = dirname(__FILE__) . '/../cache/twitter-json.txt';
    $data = file_get_contents('http://api.twitter.com/1/statuses/user_timeline/screen_name.json?count=3&include_rts=true&include_entities=true'); 

    $cachefile = fopen($cache, 'wb');
        fwrite($cachefile,utf8_encode($data));
        fclose($cachefile);
?>

现在,当我在本地运行应用程序时,这段代码运行良好,但由于某种原因,当我将它部署到服务器时它无法运行。 它会在服务器上创建缓存文件以及我添加的任何测试数据,以检查文件写入过程是否有效。

我没有自己设置服务器,它是由外部公司运行的,我只是使用 ftp 命令来部署 Web 应用程序

任何帮助和想法将不胜感激

【问题讨论】:

    标签: twitter feed timeline


    【解决方案1】:

    与您的主机核实 - 出于安全原因,他们几乎肯定不允许使用 file_get_contents。

    你的选择是

    1. 要求他们通过将 php.ini 编辑为 allow_url_fopen 来启用它
    2. 使用 cURL 拨打电话

    这是一个在 php 中使用 curl 的基本示例

    $url = "http://api.twitter.com/1/statuses/user_timeline/screen_name.json?count=3&include_rts=true&include_entities=true"
    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($curl_handle,CURLOPT_URL,$url);
    $data = curl_exec($curl_handle);
    curl_close($curl_handle);
    

    【讨论】:

    • 谢谢你在检查任何答案之前我已经这样做了 api.twitter.com/1/statuses/user_timeline/…'; $path = '../cache/twitter-json.txt'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); file_put_contents($path, $data); ?>
    猜你喜欢
    • 1970-01-01
    • 2012-12-10
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多