1

I have created a php script which will take a userid of instagram user and will scrap ALL the followers of that user. Below is the script. The problem is when I am trying to get the total followers list of a user which have say 1 or 2 millions followers than my script is crashing after 60k usernames with error PHP Warning: in_array() expects parameter 2 to be array, null given in filename.php on line LINE NO

<?php

    require '../src/Instagram.php';

    /////// CONFIG ///////
    $username = 'USERNAME';
    $password = 'PASSWORD';
    $debug = false;

    $i = new Instagram($username, $password, $debug);
    $myfile = fopen("file.txt", "w") or die("Unable to open file");

    try {
        $i->login();
        $var = $i->getUserFollowers("432464344");
        do {
            $results = $var['users'];
            foreach($results as $result) {
                $username = $result['username'];
                $username = $username . "\n";
                fwrite($myfile, $username);
        }
        if (in_array('next_max_id', $var)) {  // <-- HERE ERROR
            $next_max_id = $var['next_max_id'];
        } else {
            break;
        }
        $var = $i->getUserFollowers("432464344", $next_max_id);
    } while (1);
} catch (InstagramException $e) {
    $e->getMessage();
    fclose($myfile);
    exit();
}
echo $count;
fclose($myfile);

Thanks and regards,

  • How Math_BigInteger can solve my issue? I am not using any counter or integer variable anywhere in my script. @snapGeek –  Jun 19 '16 at 20:36
  • Try, if Math_BigInteger solve the issue. Ref - http://stackoverflow.com/questions/4427020/is-there-a-biginteger-class-in-php – snapGeek Jun 19 '16 at 20:37

1 Answers1

0

The problem has to be with getUserFollowers function (expects parameter 2 to be array, null given). Just check the possibility where that function could return null and resolve that.

Possibilities could be, either Instagram is blocking your request and returns error or over usage of system memory in your system.

Mathan Kumar
  • 55
  • 1
  • 6
  • `getUserFollowers` function implementation is `public function getUserFollowers($usernameId, $maxid = null) { return $this->request("friendships/$usernameId/followers/?max_id=$maxid&ig_sig_key_version=".Constants::SIG_KEY_VERSION."&rank_token=$this->rank_token")[1]; }` –  Jun 19 '16 at 21:08
  • It seems you are using Instagram-API by mgp25(https://github.com/mgp25/Instagram-API/blob/master/src/Instagram.php). And if you check in the request function, it is returning `array($header, json_decode($body, true))`.. If $body of the network call is null, your getUserFollowers will also return null. So, without blindly returning the result in the function getUserFollowers, handle the exception. As I mentioned earlier, the problem in network call could be because of Instagram blocking your request as you are sending it continuously. Adding sleep function might help to fix the issue. – Mathan Kumar Jun 19 '16 at 21:59
  • How much sleep time can fix this issue between each call? –  Jun 19 '16 at 22:40