繁体   English   中英

mgp25 Instagram-API 太多 API 请求

[英]mgp25 Instagram-API too many API requests

我想获得两个输入用户的所有关注者。 我这样做了,但是当尝试用户有 100 万粉丝时,例如(500 万等),我从 Instagram 收到了这个错误。

在我的例子中:

-> User1 有 500 万粉丝

-> User2 有 7 个百万粉丝

我需要获取这些用户的关注者,然后存储两个数组并相互比较。

我这样做了,但只有小帐户...

出了点问题:由于 API 请求过多而被 Instagram 限制。 出了点问题:由于 API 请求过多而被 Instagram 限制。

这是我的代码:

    require 'vendor/autoload.php';

\InstagramAPI\Instagram::$allowDangerousWebUsageAtMyOwnRisk = true;

$username = 'test_35_1041';
$password = '*****';

$ig = new \InstagramAPI\Instagram();

try {
    $ig->login($username,$password);
} catch (\Exception $e) {
    echo $e->getMessage();
}
if (!empty($_POST)){

    $name1 = $_POST["username1"];
    $name2 = $_POST["username2"];

    $userId = $ig->people->getUserIdForName($name1);
    $userId2 = $ig->people->getUserIdForName($name2);

    $items = array();
    $items2 = array();

    $time_start = microtime(true);
   try {
        $maxId = null;
        $rankToken = \InstagramAPI\Signatures::generateUUID();
        do {
            $response = $ig->people->getFollowers($userId,$rankToken,null,$maxId);
            $json = json_decode($response);
            foreach ($json->users as $value) {
                # code...
                $items[] = $value->username;
                //print_r($value->username);
            }
            $maxId = $response->getNextMaxId();
            flush();
        } while ($maxId !== null);
    } catch (\Exception $e) {
        echo 'Something went wrong: '.$e->getMessage()."\n";
    }

    try {
        $maxId = null;
        $rankToken = \InstagramAPI\Signatures::generateUUID();
        do {
            $response = $ig->people->getFollowers($userId2,$rankToken,null,$maxId);
            $json = json_decode($response);
            foreach ($json->users as $value) {
                # code...
                $items2[] = $value->username;
                //print_r($value->username);
            }
            $maxId = $response->getNextMaxId();
        } while ($maxId !== null);
    } catch (\Exception $e) {
        echo 'Something went wrong: '.$e->getMessage()."\n";
    }
    $time_end = microtime(true);
    $execution_time = ($time_end - $time_start)/60;

    $result = array_intersect($items, $items2);
}

我认为它更复杂,我需要优化此代码以获得您的帮助...我该如何解决这个问题?

感谢大家。

由于 API 请求过多而被 Instagram 限制

这意味着您经常发送请求。 你需要像这样在每个循环步骤上睡觉

try {
    $maxId = null;
    $rankToken = \InstagramAPI\Signatures::generateUUID();
    do {
        ****
        Log::info( "Sleeping for 5s...");
        sleep(5);
    } while ($maxId !== null);
} catch (\Exception $e) {
    echo 'Something went wrong: '.$e->getMessage()."\n";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM