【问题标题】:Twython API - How to see which of my 'friends' are following a specific user?Twython API - 如何查看我的哪些“朋友”正在关注特定用户?
【发布时间】: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


    【解决方案1】:

    我认为可能有更简单的解决方案。 Twitter 有一个GET friendships/show 端点,可让您查看是否有人使用“源用户”和“目标用户”的输入来关注其他人。如果他们确实跟随他们,则返回 true。

    第 1 步将生成您的 Twitter 关注者列表,第 2 步将使用他们的用户名/用户 ID 作为“源”用户以及您希望使用的其他任何用户作为“目标”用户。

    Twython 应该支持这个端点,我在docs here 中找到了它。

    【讨论】:

      猜你喜欢
      • 2015-09-30
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多