标题大致概括了这一点:我找不到任何使用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参数数组。