Twitter API throws error : 'API' object has no attribute 'search'

Twitter API throws error : 'API' object has no attribute 'search'

我编写的以下代码旨在转发带有#programming 的推文。但是,任何我 运行 代码我得到一个错误“搜索”对象不是 Twitter API 的属性。错误发布在代码下方。谢谢

import tweepy
import time 

# get api code and password(secret)
comsumers_key = '#########'
comsumers_secret = '######'

token_key = '#########'
token_secret = '###########'


auth = tweepy.OAuthHandler(comsumers_key,comsumers_secret)
auth.set_access_token(token_key, token_secret)

api = tweepy.API(auth)

hashtag = "programming"
tweetNum = 20
tweets = tweepy.Cursor(api.search, hashtag).items(tweetNum)


def bot1():
    for tweet in tweets:
        try:
            tweet.retweet()
            print("retweet")
            time.sleep(50)
        except tweepy.TweepError as e:
            print(e.reason)
            time.strftime(20)
bot1()

错误:

Traceback (most recent call last):
  File "/Users/sonter/tweetbot/bot1.py", line 48, in <module>
    tweets = tweepy.Cursor(api.search, hashtag).items(tweetNum)
AttributeError: 'API' object has no attribute 'search'

Cursor expects a regular api method, but looking at its reference doc没有search而已,但是:

  • search_30_day
  • search_full_archive
  • search_tweets
  • search_users
  • search_geo

也许您指的是其中之一?