Caveman1515
Caveman1515

Reputation: 81

Trying to find follower count in Instagram API

I am looking to find the follower count for a particular user much like you get if you were using the Instagram API Console:

from instagram.client import InstagramAPI
access_token = "Access Token"
api = InstagramAPI(access_token=access_token)
user_info = api.user(user_id)
print user_info

What I am getting from the API console when I search the user_id

{
    "meta":  {
         "code": 200
    },
    "data":  {
    "username": "IGname",
    "bio": "Comments,
    "website": "http://instagram,
    "profile_picture":             "picture",
    "full_name": "IGRealname",
    "counts":  {
        "media": Number1,
        "followed_by": Number2,
        "follows": Number3
    },
    "id": "IGUserID"
}

I am looking to get the username, follows, and followed by fields to output to python.

All I am getting is the username and that is it.

Upvotes: 2

Views: 3114

Answers (2)

You can use this:

user_followers, next_ = api.user_followed_by() 
            while next_:
                    more_user_followers, next_ = api.user_followed_by(with_next_url=next_) #this will get you all your followers
                    user_followers.extend(more_user_followers)

len(user_followers) #this is the numbers of followers you have

Upvotes: 1

Tiago Gouvêa
Tiago Gouvêa

Reputation: 16740

When you call for user info it will be returned to you. The endpoint is: https://api.instagram.com/v1/users/USERID/

The data you want are in the "counts" array.

BUT, in your example, the user are probably private. When it is private you can't get counts nether medias. The response will have 400 header (BAD REQUEST) and the body will be:

{"meta":
   {"error_type":"APINotAllowedError",
    "code":400,"error_message":"you cannot view this resource"
   }
 }

If you wish, comment here the user id to we double check it.

Upvotes: 0

Related Questions