简体   繁体   中英

Instagram API Comments Created using Python (ERROR: AttributeError)

I trying out Instagram API using python and I am new to it. Hope you could take a look at it and help me out.

I am wondering how to collect the date & time from users that have commented for each media id.

I have tried using 'created_time' but it did not manage to collect anything. Any ideas how to troubleshoot it? Or is there something wrong with my code? I manage to print out username & their comments though.

Here is my code:

from instagram.client import InstagramAPI

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):
        pass

AttributeError: 'Comment' object has no attribute 'created_time'

Unfortunately, Instagram is not very consistent in their API. The creation time of a media object is called created_time , but for a comment it is created_at .

Also note there's no need to request the comments separately: they are already available for each media object, in media.comments .

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