How can I get a list of followers from one instagram account?

两盒软妹~` 提交于 2019-12-08 02:46:56

问题


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

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" } }

回答1:


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.

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;
    }
}

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);

You can obtain right cookies doing login action on Instagram web.



来源:https://stackoverflow.com/questions/40648546/how-can-i-get-a-list-of-followers-from-one-instagram-account

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!