Search code examples
pythonpython-2.7instagrampython-2.xinstagram-api

Instagram API: 'User' object has no attribute 'counts'


I'm using Python's python-instagram library to access users/user-id endpoint of Instagram API:

According to the documentation, this is the ideal response that the above endpoint generates:

{
    "data": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
        "bio": "This is my bio",
        "website": "http://snoopdogg.com",
        "counts": {
            "media": 1320,
            "follows": 420,
            "followed_by": 3410
        }
}

Now, I'm trying to find the data associated with the counts attribute from the generated response:

from instagram.client import InstagramAPI
access_token = <my_access_token>

api = InstagramAPI(client_secret='xxxxxxxx', access_token = access_token[0])
usr = api.user_search('XXXXX')

print usr[0].counts

However, I'm encountering the following error:

AttributeError: 'User' object has no attribute 'counts'

What seems to be wrong with my code?


Solution

  • The user_search method return a list of user with limited information:
    'bio', 'full_name', 'id', 'profile_picture', 'username', 'website'

    You must access each user of the list with is id and then you can use the counts attribute : first_user = api.user(usr[0].id) then first_user.counts.