首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mgp25 Instagram-API太多的API请求

mgp25 Instagram-API太多的API请求
EN

Stack Overflow用户
提问于 2019-10-02 14:28:19
回答 1查看 4.4K关注 0票数 2

我想让所有的追随者两个进入用户。我这样做了,但是当用户尝试时有一百万的追随者,例如(500万,等等),我从Instagram上得到了这个错误。

在我的例子中:

-> User1有500万粉丝

-> User2有7名追随者

我需要得到这些用户的追随者,然后存储两个数组并相互比较。

我做了这件事,但只有小额账户.

出了问题:由于太多的API请求,Instagram限制了它。出了点问题:由于太多的API请求,Instagram把它勒死了。

这里我的代码:

代码语言:javascript
复制
    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);
}

我认为这更复杂,ı需要为您的帮助优化这段代码,请.ı如何解决这个问题?

谢谢大家。

EN

回答 1

Stack Overflow用户

发布于 2019-10-28 00:33:06

因过多的API请求而被Instagram控制

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

代码语言:javascript
复制
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";
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58203614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档