2015-06-27 56 views
0

我的问题很奇怪(至少对我来说),因为我有一个请求URL在控制台中工作,但在我的PHP脚本中抛出了Sorry, that page does not exist错误,即使连接已启动并正在运行。Twitter API - 如何检查用户A是否跟随用户B

所以这

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_secret']); 
$user = $connection->get('account/verify_credentials'); 
print_r($user); 

的伟大工程,在$用户数据被打印在屏幕上。

但是,我无法检查的友谊状态:

$x = $connection->get('https://api.twitter.com/1.1/friendships/show.json?source_id=707482092&target_id=755811768&target_screen_name=assetspersonifi'); 

当我得到的错误。

当我将这个请求放入Twitter API控制台时,它将返回json,我没有在我的php代码中收到这个请求。

我使用Abraham's twitteroauth library但是,这并不工作之一:

$follows_faelazo = $connection->get('friendships/exists', array('user_a' => 'blfarago', 'user_b' => 'faelazo')); 
if(!$follows_faelazo){ 
    echo 'You are NOT following @faelazo!'; 
    $connection->post('friendships/create', array('screen_name' => 'faelazo')); 
} else { 
    print_r($follows_faelazo); 
} 

stdClass Object ([errors] => Array ([0] => stdClass Object ([message] => Sorry, that page does not exist [code] => 34))) 

我读了friendships/exists API是由Twitter的API不再支持,我应该使用friendships/show但如何,如果你看到它不工作以上?

为了证明别人是工作的一切,我可以跟着别人用

$connection->post('friendships/create', array('screen_name' => 'faelazo')); 

为什么?

+0

这是一个明确定义的问题,显示我需要什么,我尝试了什么,为什么downvote? – erdomester

+0

1.确保您已更新API版本变量(https://github.com/abraham/twitteroauth/blob/master/src/TwitterOAuth.php#L18)2.考虑使用用户标识('source_id' 'target_id')。你能确定这些用户真正存在吗? –

回答

2

我找到了一种方法。 Here's the documentation

$following = $connection->get('friendships/show', array(
    'source_screen_name' => $_SESSION['username'], 
    'target_screen_name' => $screen_name_to_follow, 
)); 
0

另一种方法是

$following = $connection->get('friendships/lookup', array('screen_name' => $screen_name_to_follow)); 

去查Twitter doc

相关问题