Paata
Paata

Reputation: 19

When I request from instagram user info it's return only user name

I use this python library:

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

I couldn't receive this answer:

{
    "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
        }
}

how i could retrive bio, followers count an etc. info? thankyou

Upvotes: 0

Views: 1348

Answers (1)

Tony Bathgate
Tony Bathgate

Reputation: 392

You actually are receiving the entire response, but the Python version of the Instagram API client is returning instances of their User class (inherits from the ApiModel class).

You can get all the data you need by accessing those properties individually:

user = api.user('1574083')
print user.username
print user.full_name
print user.profile_picture
print user.bio
print user.website
print user.counts 

Which prints:

snoopdogg
snoopdogg
http://scontent.cdninstagram.com/hphotos-xap1/t51.2885-19/11186934_976841435684008_1692889037_a.jpg
Get BUSH now!
http://smarturl.it/BushAlbum
{u'media': 19019, u'followed_by': 6746636, u'follows': 1707}

This is deceptive because if you just print the user you will only see User: snoopdogg. In Python its possible to overwrite a lot of methods that wouldn't be allowed in other languages. Specifically here they've overwritten __str__, __repr__, and __unicode__ which are all used to convert objects to string-type objects for printing.

It is my understanding that __str__ and __unicode__ should be the "pretty" version, while __repr__ should show you (if possible) how you can reconstruct the object. They've done a pretty weak job of accomplishing either goal, but it is arguably better than the default representation of an object, which would be something like <instagram.models.User object at 0xf8c5a750>.

Upvotes: 2

Related Questions