如何从一个instagram帐户获取关注者列表? [英] How can I get a list of followers from one instagram account?
问题描述
我正在建立一个网站,我所需要的只是一个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请求的输出:-
Output of API request:-
{ ["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.
但是有一个更简单的解决方案.您只需一个电话就可以从Web版本(wihout 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帐户获取关注者列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!