2016-05-15 34 views
2

标题几乎总结了一下:我找不到任何页面使用获取状态与Twitter API。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}]} 

回答

2

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

+0

对不起,这是一个错字..它仍然不工作,得到相同的错误信息 – Charles

+0

@Charles我更新了答案,请看看 –

相关问题