【发布时间】:2021-01-23 16:47:32
【问题描述】:
正如您在桌面 Twitter 应用程序上拍摄的这张照片中看到的(尽管移动应用程序中也出现了类似的情况)example.jpgexample2.jpg也在跟随,一个方便的小清单弹出告诉你谁是罪魁祸首。我需要简明扼要地提取这些信息,但我正在努力研究如何最好地使用我们每 15 分钟间隔进行的有限(约 200 个)API 调用来处理它。
目前,使用 Twython 库 (https://twython.readthedocs.io/en/latest/api.html) 我正在收集我当前使用“get_friends_ids”关注的用户 ID 列表,然后使用循环遍历它们以检查该用户是否使用“关注我的目标” show_friendship”方法。这是代码的sn-p:
users = client.get_friends_ids(screen_name=$name)
users = users['ids']
target = client.show_user(screen_name=$target)
target = target['id']
purged = 0
worker = 0
counter3 = 0
for guy in users:
counter3 += 1
stringy = str(counter3)
print("Found " + stringy + " users to sift through")
for guy in users:
worker += 1
print("Working on user #" + str(worker))
result = client.show_friendship(source_id=guy, target_id=target)
result = result['relationship']['source']['following']
remaining = api.get_lastfunction_header(header='x-rate-limit-remaining')
API = int(remaining)
print("We have " + str(API) + "API Calls remaining")
if API <= 20:
time.sleep(60)
if API <= 5:
time.sleep(900)
if result == True:
purged += 1
client.destroy_friendship(id=guy)
print("Purging relationship with userid " +str(guy))
else:
continue
这对于关注
谢谢
【问题讨论】:
标签: python api twitter twitter-oauth twython