0
我使用Python的庫訪問users/user-id
端點Instagram的API的:Instagram的API:「用戶」對象有沒有屬性「罪名」
根據文檔,這是理想的響應,上述終端產生:
{
"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'
我的代碼似乎有什麼問題?
打印usr [0] ['counts']引發錯誤。這是dir(usr [0])返回的內容:'['__class__','__delattr__','__dict__','__doc__','__format__','__getattribute__','__hash__','__init__','__module__', '__new__','__reduce__','__reduce_ex__','__repr__','__setattr__','__sizeof__','__str__','__subclasshook__','__unicode__','__weakref__','bio','full_name','id ','object_from_dictionary','profile_picture','用戶名','網站']'。打印usr [0]返回這個:'用戶:XXXX' –
好吧,它似乎搜索返回用戶列表與以下信息:**'生物','full_name','id','profile_picture','用戶名','網站'**。所以你不能使用** counts **屬性。你必須得到用戶的信息與他的ID:** ex_user = api.user(usr [0] .id)**然後** ex_user.counts ** – Knep
謝謝,這工作。你能更新你的答案嗎? –