簡體   English   中英

Python-Twython API出現問題

[英]Python - Trouble with Twython api

我已經編寫了一個使用Twython與Twitter進行交互的python腳本。 它將關注者列表下載到一個變量中(跟隨者),將我關注的人列表下載到另一個變量中(朋友)。 然后,它應該自動跟隨所有關注我但尚未關注的人。

for fol in followers:
    if fol not in friends:
        twitter.create_friendship(fol)

我得到的錯誤是twitter.create_friendship恰好需要一個參數,但給出了兩個參數。 我看不到如何給它兩個參數,我只能看到一個。

create_friendship()是一個綁定方法,這意味着它將僅使用self參數。 它不需要任何其他位置參數,但是您要傳入fol ,現在給它兩個參數( selffol )。

該方法應改為傳遞關鍵字參數:

twitter.create_friendship(user_id=fol)

如果fol是用戶ID,或者

twitter.create_friendship(screen_name=fol)

如果fol是屏幕名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM