我正在使用Python的python-instagram
库来访问Instagram API的users/user-id
端点:
根据文档,这是上述端点生成的理想响应:
{
"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
}
}
现在,我正在尝试从生成的响应中找到与counts
属性关联的数据:
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
但是,我遇到以下错误:
AttributeError: 'User' object has no attribute 'counts'
我的代码似乎有什么问题?
答案 0 :(得分:2)
user_search方法返回信息有限的用户列表:
'bio','full_name','id','profile_picture','用户名','网站'
您必须使用ID访问列表中的每个用户,然后才能使用计数属性:
first_user = api.user(usr[0].id)
然后first_user.counts
。