我想让所有的追随者两个进入用户。我这样做了,但是当用户尝试时有一百万的追随者,例如(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);
}我认为这更复杂,ı需要为您的帮助优化这段代码,请.ı如何解决这个问题?
谢谢大家。
发布于 2019-10-28 00:33:06
因过多的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";
}https://stackoverflow.com/questions/58203614
复制相似问题