Instagram API评论created_time使用python

时间:2015-06-17 07:44:52

标签: python api python-2.7 instagram instagram-api

我试图根据用户对每个caption.id的评论来获取created_time。我能够获得用户名和&评论来自用户的文本,但我如何获得created_time?

我的代码有什么问题吗?如果没有,无论如何都要获得用户评论的created_time?谢谢。

这是我的代码:

from instagram.client import InstagramAPI
import codecs
import json 
import re


access_token = "XXX"
client_secret = "XXX"

api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="476132155")

while next_:
    more_media, next_ = api.user_recent_media(with_next_url=next_)
    recent_media.extend(more_media)

for media in recent_media:
    try:
        comments = api.media_comments(media.id)

        for i in comments:
            print i.created_time

    except (UnicodeEncodeError, AttributeError, SyntaxError):
        pass

1 个答案:

答案 0 :(得分:1)

使用created_at而不是created_time。

来自instagram.client的

导入InstagramAPI 导入编解码器 导入json 导入重新

access_token =" XXX" client_secret =" XXX"

api = InstagramAPI(access_token = access_token,client_secret = client_secret) recent_media,next_ = api.user_recent_media(user_id =" 476132155")

而next_:     more_media,next_ = api.user_recent_media(with_next_url = next_)     recent_media.extend(more_media)

对于recent_media中的媒体:     尝试:         comments = api.media_comments(media.id)

    for i in comments:
        print i.created_at

except (UnicodeEncodeError, AttributeError, SyntaxError):
    pass