William Pratt
William Pratt

Reputation: 31

Why can I not get media calls from the instagram API?

I am starting to learn the instagram API but seem to have already hit a snag. I am trying to use the very simple examples listed on the github repository. here is the code I am executing;

from instagram.client import InstagramAPI


client_id = 'xxx'
client_secret = 'xxx'
access_token = 'xxx'
client_ip = '192.168.0.3'
api = InstagramAPI(access_token=access_token,client_id=client_id,client_secret=client_secret)



recent_media, next_ = api.user_recent_media(user_id="xxx", count=10)
for media in recent_media:
print media.caption.text

everything seems to be working and all my modules are installed, but when I run the code I get the following error in the python shell;

Traceback (most recent call last):
  File "/home/william/test2.py", line 12, in <module>
    recent_media, next_ = api.user_recent_media(user_id="xxxx", count=10)
  File "/usr/local/lib/python2.7/dist-packages/instagram/bind.py", line 197, in _call
return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/instagram/bind.py", line 189, in execute
content, next = self._do_api_request(url, method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/instagram/bind.py", line 151, in _do_api_request
obj = self.root_class.object_from_dictionary(entry)
  File "/usr/local/lib/python2.7/dist-packages/instagram/models.py", line 99, in object_from_dictionary
for comment in entry['comments']['data']:
KeyError: 'data'

Does anyone have any ideas on how to fix this?

Thanks very much!

Upvotes: 3

Views: 636

Answers (1)

Dublin Anondson
Dublin Anondson

Reputation: 26

This was answered here.

  1. Find your local copy of models.py
  2. Go to line 99, it should look like this:

    for comment in entry['comments']['data']: 
        new_media.comments.append(Comment.object_from_dictionary(comment))
    
  3. add this line right above it: if "data" in entry["comments"]:
  4. adjust the next two lines below to account for the new if statement added

    if "data" in entry["comments"]:
        for comment in entry['comments']['data']: 
           new_media.comments.append(Comment.object_from_dictionary(comment))
    

That should fix it.

Upvotes: 1

Related Questions