簡體   English   中英

Tweepy AttributeError: 'API' object 沒有屬性 'search'

[英]Tweepy AttributeError: 'API' object has no attribute 'search'

我正在嘗試使用tweepy獲取推文,但我遇到了這個錯誤:

AttributeError: 'API' object 沒有屬性 'search'

代碼:

import tweepy

# Authentication
consumerKey = "Type your consumer key here"
consumerSecret = "Type your consumer secret here"
accessToken = "Type your accedd token here"
accessTokenSecret = "Type your access token secret here"

auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth)
#Sentiment Analysis

def percentage(part,whole):
    return 100 * float(part)/float(whole) 

keyword = input("Please enter keyword or hashtag to search: ")
noOfTweet = int(input ("Please enter how many tweets to analyze: "))


tweets = tweepy.Cursor(api.search, q=keyword).items(noOfTweet)

我怎樣才能解決這個問題?

使用api.search_tweets而不是api.search
tweepy v.4.0.0 改變了它..

利用:

tweets = tweepy.Cursor(api.search(q=keyword)).items(noOfTweet)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM