2017-01-20 6 views
0

私のPythonプロジェクトの1つにtweepyライブラリを使用しようとしています。 tweepyカーソルを作成してユーザーのタイムラインステータスメッセージを取得する次のコードを試すと、countパラメータは常に無視されます。tweepyでuser_timelineを照会するときにcountパラメータが無視されます

def search(self, username, keyword, consumer_key, consumer_secret, access_token, access_token_secret): 
    #start twitter auth 
    try: 
     auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
     auth.set_access_token(access_token, access_token_secret) 
     api = tweepy.API(auth) 
     user = api.get_user(username) 
    except Exception as e: 
     print(str(e)) 
     self.error = str(e) 
     return 
    self.followercount = user.followers_count 
    self.screenname = user.screen_name 
    results = [] 
    for status in tweepy.Cursor(api.user_timeline, id=username, count=2).items(): 
     try: 
      tweet = status._json 

この例では、カウントはCursorオブジェクトで2に設定されていますが、すべてを受け取ります。私は間違って何をしていますか?

答えて

1

tweepy.Cursor()は、count引数を認識していないようです。実際、counttweepy/cursor.pyのどこにも記載されておらず、モジュールtweepy.Cursorが定義されています。

for status in tweepy.Cursor(api.user_timeline, id=username).items(2): 

countキーワード引数としての代わりにitems()に制限を渡します。その代わりに、それはあなたが使用する場合がありますように見えます。 tweepy Cursor tutorialthis sectionを参照してください。

+0

私が '.items(2)'を使うと、結果はゼロですが、引数なしで '.items()'を使うと結果が返ってきます。これは本当に奇妙です。なぜなら、ドキュメントはitem(n)がうまくいくと示唆しているからです。 –

+0

それは非常に奇妙です。 '.items()'だけを使うとすべての項目が返されますか? '.pages(n)'の使用は期待通りに機能しますか? – elethan

+0

返信が遅れて申し訳ありません。今日、この質問についての通知が届きました。いくつかの試行錯誤をした後、 'items(n)'はその時に動作しました。 –

関連する問題