首页 文章

如何从一个Instagram帐户中获取关注者列表?

提问于
浏览
2

我正在 Build 一个网站,我需要的是一个Instagram帐户的关注者列表 . 我已经完成了使用auth 2.0验证我的网络应用程序的步骤 . 我刚刚意识到,通过此身份验证,我只能访问每个访问令牌所属的帐户的关注者 .

有没有其他方法可以从我想要的帐户访问关注者?

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

1 回答

  • -1

    您的client_id可能处于沙盒模式 . 您无法从白名单以外的帐户获取信息 . 如果您向应用程序发送评论,则可以退出沙盒模式 .

    但是有一个更简单的解决方案 . 您只需拨打一个电话即可从网络版(无需API)获取公开信息:

    $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. 对不起,我误解了你的问题 . 可以在没有API的情况下获取列表 . 您需要cookie中的csrf令牌和用户ID,然后调用查询:

    $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进行登录操作 .

相关问题