我的问题很奇怪(至少对我来说),因为我有一个可以在控制台中使用的请求URL,但是Sorry, that page does not exist即使连接已建立并正在运行,它也会在我的php脚本中引发错误。
所以这
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_secret']);
$user = $connection->get('account/verify_credentials');
print_r($user);
Run Code Online (Sandbox Code Playgroud)
效果很好,$ user数据被打印在屏幕上。
但是,我无法通过以下方式检查友谊状态:
$x = $connection->get('https://api.twitter.com/1.1/friendships/show.json?source_id=707482092&target_id=755811768&target_screen_name=assetspersonifi');
Run Code Online (Sandbox Code Playgroud)
当我得到错误。
当我将此请求放入Twitter API控制台时,它会返回我在php代码中未收到的json。
我正在使用亚伯拉罕的twitteroauth库,但这也不起作用:
$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 ) ) )
Run Code Online (Sandbox Code Playgroud)
我读到friendships/existsTwitter API不再支持该API,我应该使用该API,friendships/show但是如上所示,该API 如何不起作用?
为了证明其他所有功能都可以正常工作,我可以跟其他人一起
$connection->post('friendships/create', array('screen_name' => 'faelazo'));
Run Code Online (Sandbox Code Playgroud)
为什么?
我找到了一个方法。这是文档
$following = $connection->get('friendships/show', array(
'source_screen_name' => $_SESSION['username'],
'target_screen_name' => $screen_name_to_follow,
));
Run Code Online (Sandbox Code Playgroud)