1

Twython を使用して Python で Twitter API を操作しようとしていますが、奇妙な動作を観察しています。

次のコードを実行すると...

from twython import Twython
from random import randint

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) # In the actual code, I obviously assign these, but I can't disclose them here, so the code won't work...

user_id = randint(1,250000000)
twitter_user = twitter.lookup_user(user_id)

このエラーが発生します。

Traceback (most recent call last):

File "Twitter_API_Extraction.py", line 76, in <module>
twitter_user = twitter.lookup_user(user_id) # returns a list of dictionaries with all the users requested
TypeError: lookup_user() takes exactly 1 argument (2 given)

Twython ドキュメントは、ユーザー ID またはスクリーン名 ( https://twython.readthedocs.org/en/latest/api.html )を渡すだけでよいことを示しています。いくつかのグーグルは、このエラーは通常、最初のパラメーターとして自分自身を渡す必要があることを意味することを示唆していましたが、その理由はよくわかりませんでした.

ただし、代わりに次の割り当てを使用すると...

twitter_user = twitter.lookup_user(user_id = randint(1,250000000))

すべてがバラになります。これがなぜなのかわかりません。コードの後半で、同じ lookup_user 関数を使用してフォロワーにアクセスしようとすると問題になります。

このエラーの原因と、関数呼び出しでの代入を介してそれをバイパスする方法についての明確化をいただければ幸いです!

4

2 に答える 2