Using the Instagram API to get ALL followers

风流意气都作罢 提交于 2019-11-27 13:15:53

问题


I'm using the Instagram API to get the number of people who follow a given account as follows.

$follow_info = file_get_contents('https://api.instagram.com/v1/users/477644454/followed-by?access_token=ACESS_TOKEN&count=-1');
$follow_info = @json_decode($follow_info, true);

This returns a set of 50 results. They do have a next_url key in the array, but it becomes time consuming to keep on going to the next page of followers when dealing with tens of thousands.

I read on StackOverflow that setting the count parameter to -1 would return the entire set. But, it doesn't seem to...


回答1:


Instagram limits the number of results returned in their API for all sorts of endpoints, and they change these limits arbitrarily, without warning, presumably to handle server load.

Several similar threads exist:

  • Instagram API not fufilling count parameter
  • Displaying more than 20 photos in instagram API
  • Instagram API: How to get all user media? (see comments on answer too, -1 returns 1 less result).
  • 350 Request Limit for Instagram API
  • Instagram API: How to get all user media?

In short, you won't be able to increase the maximum returned rows, and you'll be stuck paginating.




回答2:


$follow_info = file_get_contents('https://api.instagram.com/v1/users/USER_ID?access_token=ACCES_TOKEN');
$follow_info = json_decode($follow_info);
print_r($follow_info->data);

And:

return
{
  "meta":  {
    "code": 200
  },
  "data":  {
    "username": "i_errorw",
    "bio": "A Casa do Júlio é um espaço para quem gosta da ideia de cuidar da saúde com uma alimentação saudável e saborosa.",
    "website": "",
    "profile_picture": "",
    "full_name": "",
    "counts":  {
      "media": 5,
      "followed_by": 10,
      "follows": 120000
    },
    "id": "1066376857"
  }
}



回答3:


if the APIs are optional

using the mobile version of twitter you can extract a full list of a followers for a designed target using a very simple bash script

the sleep time must me chosen carefully to avoid temporary ip block

the script can be executed by :

./scriptname.sh targetusername

content

   #!/bin/bash

    counter=1 

    wget --load-cookies ./twitter.cookies -O - "https://mobile.twitter.com/$1/followers?" > page 


    until [ $counter = 0 ]; do

    cat page | grep -i "@" | grep -vi "fullname" | grep -vi "$1" | awk -F">" '{print $5}' | awk -F"<" '{print $1}' >> userlist

    nextpage=$(cat page | grep -i "cursor" | awk -F'"' '{print $4}')

    wget --load-cookies twitter.cookies -O - "https://mobile.twitter.com/$nextpage" > page

    if [ -z $nextpage ]; then 

    exit 0

    fi

    sleep 5 

    done

it creates a file "userlist" including all usernames that follows the designed target one by line

PS: a cookies file filled with your credentials is necessary to wget to authenticate the requests




回答4:


I personally suggest to use Wizboost for instagram automation. And the reason is that I have used this tool and my experience is amazing. It gave me a lot of followers. Now you don’t need to invest time in competing with other Instagram accounts as Wizboost has got your back for this, in fact for everything. You don’t need to do anything you can just relax and Wizboost will get you followers, likes and comments. And you can also schedule your posts too. So easy to use and still got lots of potential. I just love Wizboost for all the services it has.




回答5:


$follow_info = file_get_contents('https://api.instagram.com/v1/users/USER_ID?access_token=ACCES_TOKEN');
$follow_info = json_decode($follow_info);
print_r($follow_info->data);

return
{
  "meta":  {
    "code": 200
  },
  "data":  {
    "username": "casadojulio",
    "bio": "A Casa do Júlio é um espaço para quem gosta da ideia de cuidar da saúde com uma alimentação saudável e saborosa.",
    "website": "",
    "profile_picture": "",
    "full_name": "",
    "counts":  {
      "media": 5,
      "followed_by": 25,
      "follows": 12
    },
    "id": "1066376857"
  }
}


来源:https://stackoverflow.com/questions/20643830/using-the-instagram-api-to-get-all-followers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!