简体   繁体   中英

Instagram API tagging using Python

I am trying to print out all the caption text that have 'Starhub' in it. It works, but I only able to print out a total of 19 text.

Found this function: api.tag_recent_media(count, max_tag_id, tag_name) - https://github.com/Instagram/python-instagram

So I make use of that function, but it failed. I type 50 counts meaning I hope that 50 text would come out, but it only print out 19 instead.

My codes:

from instagram.client import InstagramAPI
from instagram.bind import InstagramAPIError

access_token = "289615375.008d237.5f2085b9c5c6400bab78709cee949914"
client_secret = "7f79614f8fe04a569c56f8672239cb8d"

api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.tag_recent_media(count=50, tag_name="Starhub")

count = 0

for media in recent_media:
  try:
      print media.caption.text, "--->", media.user.username
      print ""
       count += 1

  except UnicodeEncodeError:
      pass

print count

This code print out only 19. So what I try to do instead is this.

I add this inside my code:

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

There is error: No paremeter value found for path variable; tag_name.

Any idea how can I print out all text that have the tag 'Starhub'?

I couldn't get with_next_url to work either. I ended up putting the max_tag_id from the 'next_' variable back into tag_recent_media's 'max_tag_id' parameter, which seems to work.

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