我试图弄清楚我是否正在关注流 API 刚刚收到推文的用户。如果我不这样做,那么我想跟随他。
我有这样的东西:
def checkFollow(status):
relationship = api.lookup_friendships("Privacy_Watch_",status.user.id_str)
从那里,我如何检查我是否已经关注了该用户?
最佳答案
lookup_friendships 方法将返回您每次调用时关注的每个人(以 100 个用户为单位)。如果您关注很多人,那么效率会非常低,并且会消耗大量请求。
您可以使用 show_friendship 来代替方法,它将返回一个包含 information 的 JSON关于您与所提供的 ID 的关系。
我现在无法测试它,但以下代码应该可以满足您的要求:
def checkFollow(status):
relation = api.show_friendship(source_screen_name=your_user_name, target_screen_name=status.user.id_str)
if relation.target.following: #I'm not sure if it should be "target" or "source" here
return True
return False
关于Python - Tweepy - 如何使用lookup_friendships?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39985434/