2014-10-10 2 views
0

예를받은추출 태그는 GitHub의에서 파이썬 - 인스 타 그램 문서에서 인스 타 그램의 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: 
    print media.tags # attempt to get tags associated with each media 

가 말한다 미디어에 "태그"속성이 없습니다. Instagram API의 응답에는 "tags"키가 포함되어 있다고 생각합니다.

무엇이 누락 되었습니까? 미디어 태그를 얻는 방법?

답변

0

우선 태그 속성이 있는지 확인해야합니다. 이와 같이 :

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)) 
+0

그렇다면 해당 미디어를 게시 한 사람이 태그를 쓰지 않았다면 태그 속성이없는 것입니까? 빈 목록을 반환하지 않습니까? – Jahongir

+0

또는'tags = getattr (media, 'tags', [])'또는 무엇이든 기본값 인 빈'tags'을 사용해야합니다. –

+0

@Jahongir 예, 그렇게 생각합니다. –

관련 문제