Python - Twython api 的问题
Posted
技术标签:
【中文标题】Python - Twython api 的问题【英文标题】:Python - Trouble with Twython api 【发布时间】:2014-10-06 13:09:45 【问题描述】:我编写了一个使用 Twython 与 twitter 交互的 python 脚本。它将关注者列表下载到一个变量(关注者)中,并将我关注的人列表下载到另一个变量(朋友)中。然后它应该自动关注所有关注我但我尚未关注的人。
for fol in followers:
if fol not in friends:
twitter.create_friendship(fol)
我得到的错误是twitter.create_friendship
只需要一个参数,但它被赋予了两个。我看不出它是如何被赋予两个参数的,我只能看到一个。
【问题讨论】:
这是create_friendship
的文档,它指向friendships.create
文档。
当你在python中调用一个函数时,你调用它的对象作为第一个参数传递。这就是为什么所有类方法都将self
作为第一个参数。
【参考方案1】:
create_friendship()
是一个绑定方法,这意味着它只需要self
参数。它不接受任何其他位置参数,但你传入fol
,现在给它两个参数(self
和fol
)。
该方法应改为传递关键字参数:
twitter.create_friendship(user_id=fol)
如果 fol
是用户 ID,或者
twitter.create_friendship(screen_name=fol)
如果fol
是一个网名。
【讨论】:
以上是关于Python - Twython api 的问题的主要内容,如果未能解决你的问题,请参考以下文章