【发布时间】: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()
如果函数或代码本身有错误,能否请您写一个正确的版本?我正在尝试为一个项目收集推文数据。
【问题讨论】: