python - When I request from instagram user info it's return only user name -
i use 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 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 bio", "website": "http://snoopdogg.com", "counts": { "media": 1320, "follows": 420, "followed_by": 3410 } }
how retrive bio, followers count etc. info? thankyou
you receiving entire response, python version of instagram api client returning instances of user
class (inherits apimodel
class).
you can data need accessing 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 bush now! http://smarturl.it/bushalbum {u'media': 19019, u'followed_by': 6746636, u'follows': 1707}
this deceptive because if print user
see user: snoopdogg
. in python possible overwrite lot of methods wouldn't allowed in other languages. here they've overwritten __str__
, __repr__
, , __unicode__
used convert objects string-type objects printing.
it understanding __str__
, __unicode__
should "pretty" version, while __repr__
should show (if possible) how can reconstruct object. they've done pretty weak job of accomplishing either goal, arguably better default representation of object, <instagram.models.user object @ 0xf8c5a750>
.
Comments
Post a Comment