Twitter API - 获取状态未找到任何用户页面

Twitter API - Get Statuses not Finding Any User Page

标题几乎概括了它:我找不到任何使用 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}]}

您在 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 参数数组。