如何使用 python-twitter 找到关注请求的用户 [英] How can I find follow requested users with python-twitter
问题描述
我正在尝试使用 python-twitter 库在列表中关注某个用户.但是我正在为某些用户处理您已经请求关注用户名"错误.这意味着我已向该用户发送了以下请求,因此我不能再这样做了.那么我如何控制用户,我发送了以下请求.或者有其他方法可以控制它.
I am trying to follow some user in a list with python-twitter library. But I am taking "You've already requested to follow username" error for some users. That means I have sent a following request to that user so I cant do that again. So how can I control users, I sent following request. Or is there other way to control it.
for userID in UserIDs:
api.CreateFriendship(userID)
我正在总结:您可以在需要时关注一些用户.但有些人不允许.首先你必须发送好友请求,然后他/她可能会接受或不接受.我想了解的是,如何列出请求的用户.
I am summerizing: You can follow some users when you want. But some ones don't let it. Firstly you must send friendship request, then he/she might accept it or not. What I want to learn is, how I can list requested users.
推荐答案
这里有两个选择:
在循环之前调用
GetFriends
:
users = [u.id for u in api.GetFriends()]
for userID in UserIDs:
if userID not in users:
api.CreateFriendship(userID)
使用try/except
:
for userID in UserIDs:
try:
api.CreateFriendship(userID)
except TwitterError:
continue
希望有所帮助.
这篇关于如何使用 python-twitter 找到关注请求的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!