gpt4 book ai didi

php - Twitter API - 如何检查用户 A 是否关注用户 B

转载 作者:行者123 更新时间:2023-12-02 17:32:33 128 4
gpt4 key购买 nike

我的问题很奇怪(至少对我而言),因为我有一个在控制台中有效的请求 URL,但在我的 PHP 脚本中抛出了 Sorry, that page does not exist 错误,即使连接已启动并正在运行。

所以这个

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

效果很好,$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 控制台时,它会返回我在我的 php 代码中没有收到的 json

我正在使用 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'));

为什么?

最佳答案

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

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

关于php - Twitter API - 如何检查用户 A 是否关注用户 B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088704/

128 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com