问题描述
我正在建立一个网站,我需要的只是来自一个 Instagram 帐户的关注者列表.我已经完成了使用 auth 2.0 对我的 Web 应用程序进行身份验证的步骤.我刚刚意识到,通过这种身份验证,我只能访问每个访问令牌所属帐户的关注者.
I am building a website and all i need is a list of followers from one Instagram account. I've gone through the steps to authenticate my web app with auth 2.0. I just realized that with this authentication I can only access the followers of the account to whom each access token belongs.
还有其他方法可以从我想要的帐户访问关注者吗?
Is there any other way that I could access the followers from my desired account?
https://api.instagram.com/v1/users/4082347837/followed-by?access_token=AccessToken
API 请求输出:-
{ ["meta"]=> object(stdClass)#2 (3) { ["error_type"]=> string(18) "APINotAllowedError" ["code"]=> int(400) ["error_message"]=> string(29) "you cannot view this resource" } }
推荐答案
可能,您的 client_id 处于沙盒模式.除了白名单之外,您无法从帐户获取信息.如果您将应用发送给您进行审核,您可以退出沙盒模式.
Probably, you client_id is in a sandbox mode. You can't get info from accounts except whitelisted. You can leave the sandbox mode if you send you app for the review.
但是有一个更简单的解决方案.只需一个电话,您就可以从网络版本(没有 API)获取公开信息:
But there is a simplier solution. You can get public info from web version (wihout API) just with one call:
$otherPage = 'nasa';
$response = file_get_contents("https://www.instagram.com/$otherPage/?__a=1");
if ($response !== false) {
$data = json_decode($response, true);
if ($data !== null) {
$follows = $data['user']['follows']['count'];
$followedBy = $data['user']['followed_by']['count'];
echo $follows . ' and ' . $followedBy;
}
}
更新.对不起,我误解了你的问题.可以在没有 API 的情况下获取列表.您需要 cookie 中的 csrf 令牌和用户 ID,然后调用查询:
Update.Sorry, I've misunderstood your question. It is possible to get the list without API. You need csrf token and user id in cookies, then call the query:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/query/");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//You need the csrftoken, ds_user_id
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: ..."));
curl_setopt($ch, CURLOPT_POST, 1);
$userId = 528817151;
curl_setopt($ch, CURLOPT_POSTFIELDS,
"q=ig_user($userId) {
followed_by.first(10) {
count,
page_info {
end_cursor,
has_next_page
},
nodes {
id,
is_verified,
followed_by_viewer,
requested_by_viewer,
full_name,
profile_pic_url,
username
}
}
}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
您可以在 Instagram 网站上执行登录操作获取正确的 cookie.
You can obtain right cookies doing login action on Instagram web.
这篇关于如何从一个 Instagram 帐户获取关注者列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!