NicklasWallgren / instagram-api

Instagram Private API
MIT License
145 stars 47 forks source link

Getting user follower count #41

Closed yigitkeremoktay closed 3 years ago

yigitkeremoktay commented 3 years ago

Hello,

I want to quickly get the following and follower count but there is no documentation to help me.

mferrara commented 3 years ago

@yigitkeremoktay - this should help get you going in the right direction



$instagram      = new Instagram();
$instagram->login($ig_username, $ig_password);
$user_session   = $instagram->client->getSession();
$user           = $user_session->getUser();
$user_id        = $user->getId();

$users  = [];
        while($followers->getNextMaxId())
        {
            foreach($followers->getUsers() as $follower)
            {
                $users[] = [
                    'id'                => $follower->getId(),
                    'username'          => $follower->getUsername(),
                    'full_name'         => $follower->getFullName(),
                    'photo_url'         => $follower->getProfilePictureUrl(),
                    'anon_photo'        => $follower->hasAnonymousProfilePicture()
                ];
            }
            $followers->next();
        }

        // Get the last page's results
        foreach($followers->getUsers() as $follower)
        {
            $users[] = [
                'id'                => $follower->getId(),
                'username'          => $follower->getUsername(),
                'full_name'         => $follower->getFullName(),
                'photo_url'         => $follower->getProfilePictureUrl(),
                'anon_photo'        => $follower->hasAnonymousProfilePicture()
            ];
        }

`
yigitkeremoktay commented 3 years ago

Where did the $followers variable come from @mferrara ?

mferrara commented 3 years ago

Oops, missed a line :D It's below, should come before the while loop.


// Get the followers for this user id
$followers = $instagram->followers($user_id);
yigitkeremoktay commented 3 years ago

Thanks!