github中python-instagram文档的示例:
from instagram.client import InstagramAPI
access_token = "YOUR_ACCESS_TOKEN"
api = InstagramAPI(access_token=access_token)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print media.caption.text # it gets caption text from each media
但是,当我尝试这个(只有最后一行改变):
from instagram.client import InstagramAPI
access_token = "YOUR_ACCESS_TOKEN"
api = InstagramAPI(access_token=access_token)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print media.tags # attempt to get tags associated with each media
它说媒体没有“标签”属性。我认为来自Instagram API的响应包括“标签”键。
我想念什么?如何获得媒体标签?
首先,您应该确保有标签属性。像这样:
from instagram.client import InstagramAPI
access_token = "YOUR_ACCESS_TOKEN"
api = InstagramAPI(access_token=access_token)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
if hasattr(media, 'tags'):
print media.tags # attempt to get tags associated with each media
else:
# you can check if there is tags attribute through this line
print 'all the attributes of media are: ', repr(dir(media))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句