简体   繁体   English

使用Python的Instagram API标记

[英]Instagram API tagging using Python

I am trying to print out all the caption text that have 'Starhub' in it. 我正在尝试打印出所有带有“ Starhub”的标题文本。 It works, but I only able to print out a total of 19 text. 它可以工作,但我只能打印总共19个文本。

Found this function: api.tag_recent_media(count, max_tag_id, tag_name) - https://github.com/Instagram/python-instagram 发现这个功能:api.tag_recent_media(计数,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. 我输入50个计数,表示希望能输出50个文本,但只能打印19个文本。

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. 此代码仅打印出19。因此,我尝试执行的操作是此代码。

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'? 知道如何打印带有“ Starhub”标签的所有文本吗?

I couldn't get with_next_url to work either. 我也无法使用with_next_url来工作。 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. 我最终将'next_'变量中的max_tag_id放回tag_recent_media的'max_tag_id'参数中,这似乎可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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