简体   繁体   中英

Instagram API Comments created_time using python

I'm trying to get created_time base on the user's comments for each caption.id. I am able to get username & comment text from users, but how do I get created_time?

Is there anything wrong with my code? If not, is there anyway to obtain created_time for user's comment? Thank you.

Here is my code:

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

use created_at instead of 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_at

except (UnicodeEncodeError, AttributeError, SyntaxError):
    pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM