【问题标题】:Abraham Twitter API 1.1 Oauth library only returning "null"Abraham Twitter API 1.1 Oauth 库仅返回“null”
【发布时间】:2013-09-26 07:44:18
【问题描述】:

我一直在尝试使用 Abraham Williams 的 Twitter Oauth 库 (https://github.com/abraham/twitteroauth) 从用户的 Twitter 提要中获取最新状态.当我在我的网站上运行它时,会显示一个全白页面,左上角显示“null”。

据我所知,我拥有的 Oauth 密钥是有效的,我使用 000webhost.com 托管我的网站,我的网络服务器使用 PHP 5.2.17 并启用了 cURL,来自我拥有的教程和示例文件一直在使用我的索引文件应该是正确的,我的网站可以在http://authortryndaadair.site90.net 找到,该调用的结果正在显示。

我已经能够解决少量问题,但我不确定还有什么可以尝试让这个 Api 调用正常工作。任何解决此问题的帮助将不胜感激。

下面是替换get_tweet1.1.php的索引文件内容:

session_start();
// Path to twitteroauth library
require_once("twitteroauth/twitteroauth/twitteroauth.php"); 

$twitteruser = "JaneSmith";
$notweets = 10;
$consumerkey = "123456";
$consumersecret = "789123";
$accesstoken = "456789";
$accesstokensecret = "1023456";

function getConnectionWithAccessToken($cons_key, $cons_secret, 
                                      $oauth_token, $oauth_token_secret) {
    $connection = new TwitterOAuth($cons_key, $cons_secret,
                                   $oauth_token, $oauth_token_secret);
    return $connection;
}

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret,
                                           $accesstoken, $accesstokensecret);
$tweets = $connection->get(
    "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" 
    . $twitteruser . "&count=" . $notweets
);

echo json_encode($tweets);

【问题讨论】:

    标签: php twitter twitter-oauth


    【解决方案1】:

    假设您正在运行最新的 TwitterOAuth 代码,get 行应如下所示。

    $tweets = $connection->get(
                  "statuses/user_timeline", 
                  array("screen_name" => $twitteruser, "count" => $notweets)
              );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 2014-02-26
      • 2023-03-09
      • 2016-09-15
      • 1970-01-01
      相关资源
      最近更新 更多