Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. /* filename : scrap.php
  3. * author : Deepanshu Thakur
  4. * e-mail : deepanshu2017@gmail.com , deepanshu2017@hotmail.com
  5. * description : This file takes a instagram userid and scrap all the
  6. * followers of that user and write into file.
  7. */
  8.  
  9. require '../src/Instagram.php';
  10. ini_set('memory_limit', '-1');
  11. define('SLEEP_TIME',1);
  12. define('TARGET_USER_ID',432464344);
  13.  
  14. /////// CONFIG ///////
  15. $username = 'USERNAME';
  16. $password = 'PASSWORD';
  17. $debug = false;
  18.  
  19. $i = new Instagram($username, $password, $debug);
  20. $myfile = fopen("FILE_NAME.txt", "w") or die("Unable to open file");
  21.  
  22. try {
  23. // Login to my account.
  24. $i->login();
  25.  
  26. // Get followers list. Instagram will return maximum of 200 users in a
  27. // single request.
  28. $var = $i->getUserFollowers(TARGET_USER_ID);
  29. do {
  30. // Take the desired field from the output.
  31. sleep(SLEEP_TIME);
  32. $results = $var['users'];
  33. foreach($results as $result) {
  34. $username = $result['username'];
  35. $username = $username . "\n";
  36. fwrite($myfile, $username);
  37. }
  38.  
  39. // While request have next page link continue with loop else break.
  40. if (in_array('next_max_id', $var)) {
  41. $next_max_id = $var['next_max_id'];
  42. $var = $i->getUserFollowers(TARGET_USER_ID, $next_max_id);
  43. } else {
  44. break;
  45. }
  46. } while (true);
  47. } catch (InstagramException $e) {
  48. $e->getMessage();
  49. fclose($myfile);
  50. exit();
  51. }
  52. fclose($myfile);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement