Skip to content

Commit

Permalink
Merge pull request #2 from adam-szabo/feature/get-followers
Browse files Browse the repository at this point in the history
Get followers
  • Loading branch information
adam-szabo authored Oct 15, 2017
2 parents fe183a8 + 66dc278 commit 993a9ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,18 @@ $medias = Instagram::getLocationTopMediasById(1);
$medias = Instagram::getLocationMediasById(1);
```

### Get followers of an account
```php
$username = 'kevin';
$followers = [];
$instagram = Instagram::withCredentials('your_username', 'hunter2');
$instagram->login();
sleep(2); // Delay to mimic browser
$account = Instagram::getAccount($username);
sleep(1);
$followers = $instagram->getFollowers($account->getId(), 1000, 100, true); // Get 1000 followers of 'kevin', 100 a time with random delay between requests
echo '<pre>' . json_encode($followers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '</pre>';
```

### Other
Java library: https://github.com/postaddictme/instagram-java-scraper
7 changes: 5 additions & 2 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ public function getFollowers($accountId, $count = 20, $pageSize = 20, $delayed =
throw new InstagramException('Count must be greater than or equal to page size.');
}

while ($index < $count) {
while (true) {
$response = Request::get(Endpoints::getFollowersJsonLink($accountId, $pageSize, $endCursor),
$this->generateHeaders($this->userSession));
if ($response->code !== 200) {
Expand All @@ -754,7 +754,10 @@ public function getFollowers($accountId, $count = 20, $pageSize = 20, $delayed =

foreach ($edgesArray as $edge) {
$accounts[] = $edge['node'];
$index++;
$index++;
if ($index >= $count) {
break 2;
}
}

$pageInfo = $jsonResponse['data']['user']['edge_followed_by']['page_info'];
Expand Down

0 comments on commit 993a9ee

Please sign in to comment.