【问题标题】:Tweepy error when trying to gather Tweets尝试收集推文时出现 Tweepy 错误
【发布时间】:2022-01-09 10:59:58
【问题描述】:

我正在尝试使用 Python 中的 Tweepy 模块获取推文。但是,每当我尝试使用 tweepy.Cursor 函数收集推文时,它都会返回错误:

TweepyException                           Traceback (most recent call last)
<ipython-input-5-a26c992842dc> in <module>
----> 1 tweets_list = tweepy.Cursor(api.search_tweets(q="oranges", tweet_mode='extended', lang='en')).items()

~\anaconda3\lib\site-packages\tweepy\cursor.py in __init__(self, method, *args, **kwargs)
     38                 raise TweepyException('Invalid pagination mode.')
     39         else:
---> 40             raise TweepyException('This method does not perform pagination')
     41 
     42     def pages(self, limit=inf):

TweepyException: This method does not perform pagination

我不知道这是为什么。我仍然可以使用api.update_status() 函数发布推文。请帮忙。这是我的代码。如您所见,设置是正确的;只有这个函数返回错误。

from config import *
import tweepy
import datetime

consumer_key= 'CONSUMER KEY HERE'
consumer_secret= 'CONSUMER KEY SECRET HERE'
access_token= 'ACCESS TOKEN HERE'
access_token_secret= 'ACCESS TOKEN SECRET HERE'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
    
try:
    api.verify_credentials()
    print("Authentication Successful")
except:
    print("Authentication Error")

tweets_list = tweepy.Cursor(api.search_tweets(q="oranges", tweet_mode='extended', lang='en')).items()

如果函数或代码本身有错误,能否请您写一个正确的版本?我正在尝试为一个项目收集推文数据。

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    您将调用/调用API.search_tweets 的结果而不是方法本身传递给Cursor

    有关如何使用Cursor 的示例,请参阅Tweepy's Pagination documentation

    【讨论】:

      猜你喜欢
      • 2022-11-19
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2018-06-29
      相关资源
      最近更新 更多