Twython API-如何查看我的哪些“朋友”关注特定用户?

问题描述

如您在台式机Twitter App上拍摄的这张照片中所见(尽管在Mobile App中也出现了类似的情况)example.jpg example2.jpg,当您访问随后关注的用户的个人资料时由您也关注的用户弹出的方便的小列表会告诉您确切的罪魁祸首。我需要简洁地提取此信息,但是我正在努力尝试如何最好地使用每15分钟一次的有限(约200个)API调用来处理它。

目前,使用Twython库(https://twython.readthedocs.io/en/latest/api.html),我正在收集当前以“ get_friends_ids”使用的用户名列表,然后通过循环遍历它们,以检查该用户是否遵循我的目标。 “ show_friendship”方法。这是代码段:

    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

这对于跟随

谢谢

解决方法

我认为可能会有一个更简单的解决方案。 Twitter有一个GET friendships/show端点,它使您可以查看是否有人使用“源用户”和“目标用户”的输入关注了其他人。如果他们遵循它们,它将返回true。

第1步将生成您的Twitter关注者的列表,第2步将将其用户名/用户ID用作“源”用户,并将您想要的其他任何用户用作“目标”用户。

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...