【问题标题】:Twitter API - Get Statuses not Finding Any User PageTwitter API - 获取未找到任何用户页面的状态
【发布时间】:2016-05-16 22:22:34
【问题描述】:

标题非常概括:我找不到任何使用 Twitter API 获取状态的页面。

这是我的代码。

<?php
session_start();
require "abraham/twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

$twitteruser = "IliaVED"; //User name I'm looking for
$id = "486654831"; //Corresponding id
$notweets = 30; //how many tweets you want to retrieve

$consumerkey = "xxx"; 
$consumersecret = "xxx";      
$accesstoken = "xxx"; 
$accesstokensecret = "xxx"; 

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);
echo $tweets;   
?>

我尝试使用 ID 而不是屏幕名称,但仍然找不到。

可以清楚的看到用户存在:https://twitter.com/IliaVED

我尝试了不同的用户,它做同样的事情..

这是我得到的错误:

{"errors":[{"message":"Sorry, that page does not exist","code":34}]}

【问题讨论】:

    标签: php twitter twitter-oauth


    【解决方案1】:

    您在 URL GET 参数部分中的 screen_name 之后缺少 =。使用:

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

    编辑:实际上,您使用库的方式有误,请尝试:

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

    库本身具有基本 URL,并将其添加到您提供的路径并处理 URL GET 参数数组。

    【讨论】:

    • 抱歉,打错字了。。还是不行,还是一样的错误信息
    猜你喜欢
    • 2015-05-13
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 2011-03-09
    • 2018-07-11
    • 2015-10-23
    • 2013-09-10
    • 1970-01-01
    相关资源
    最近更新 更多