2016-10-11 33 views
0

我试图弄清楚我是否关注流API刚刚收到推文的用户。如果我不这样做,那么我想跟着他。Python - Tweepy - 如何使用lookup_friendships?

我有一样的东西:

def checkFollow(status): 
    relationship = api.lookup_friendships("Privacy_Watch_",status.user.id_str) 

从那里,我该如何检查,如果我按照用户了吗?

+0

[此功能(http://docs.tweepy.org/en/v3.5.0/api。 html#API.exists_friendship)应该做你想做的。 – Efferalgan

+0

嘿,谢谢!我读过这个函数已被弃用,但文档没有更新。那么情况不是这样吗? – Ncollig

+0

哦,[你是对的](https://github.com/tweepy/tweepy/issues/525)。我的错。 – Efferalgan

回答

0

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 
+0

嗨!谢谢,看起来像一个解决方案。我会检查出来,让它知道如何去。 – Ncollig