未经授权:401 未经授权 32 - 无法验证您的身份
Unauthorized: 401 Unauthorized 32 - Could not authenticate you
我试图从特定位置获取与特定主题标签相关的数据,但出现错误。我在互联网上搜索可能是因为 since 但我不确定要使用什么而不是 since 才能避免出现错误并且我的代码可以正常工作?任何帮助或指导表示赞赏!
import tweepy
import datetime
TWITTER_CONSUMER_KEY = '-'
TWITTER_CONSUMER_SECRET = '-'
TWITTER_ACCESS_TOKEN = '-'
TWITTER_ACCESS_TOKEN_SECRET = '-'
auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)
api = tweepy.API(auth,wait_on_rate_limit=True)
today = datetime.date.today()
yesterday= today - datetime.timedelta(days=1)
today, yesterday
tweets_list = tweepy.Cursor(api.search_tweets, q="#Covid-19 since:" + str(yesterday)+ " until:" + str(today),tweet_mode='extended', lang='it').items()
place = 'London'
tweets_list = tweepy.Cursor(api.search_tweets, q="place: " + place,tweet_mode='extended', lang='it').items()
output = []
for tweet in tweets_list:
text = tweet._json["full_text"]
print(text)
favourite_count = tweet.favorite_count
retweet_count = tweet.retweet_count
created_at = tweet.created_at
line = {'text' : text, 'favourite_count' : favourite_count, 'retweet_count' : retweet_count, 'created_at' : created_at}
output.append(line)
错误:
Unauthorized: 401 Unauthorized
32 - Could not authenticate you.
看来您没有正确的 Twitter 权限。
您可以看到不同级别的权限here
您必须登录、更改您的权限并重新生成您的 api 密钥才能使其正常工作
祝你好运
我试图从特定位置获取与特定主题标签相关的数据,但出现错误。我在互联网上搜索可能是因为 since 但我不确定要使用什么而不是 since 才能避免出现错误并且我的代码可以正常工作?任何帮助或指导表示赞赏!
import tweepy
import datetime
TWITTER_CONSUMER_KEY = '-'
TWITTER_CONSUMER_SECRET = '-'
TWITTER_ACCESS_TOKEN = '-'
TWITTER_ACCESS_TOKEN_SECRET = '-'
auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)
api = tweepy.API(auth,wait_on_rate_limit=True)
today = datetime.date.today()
yesterday= today - datetime.timedelta(days=1)
today, yesterday
tweets_list = tweepy.Cursor(api.search_tweets, q="#Covid-19 since:" + str(yesterday)+ " until:" + str(today),tweet_mode='extended', lang='it').items()
place = 'London'
tweets_list = tweepy.Cursor(api.search_tweets, q="place: " + place,tweet_mode='extended', lang='it').items()
output = []
for tweet in tweets_list:
text = tweet._json["full_text"]
print(text)
favourite_count = tweet.favorite_count
retweet_count = tweet.retweet_count
created_at = tweet.created_at
line = {'text' : text, 'favourite_count' : favourite_count, 'retweet_count' : retweet_count, 'created_at' : created_at}
output.append(line)
错误:
Unauthorized: 401 Unauthorized
32 - Could not authenticate you.
看来您没有正确的 Twitter 权限。
您可以看到不同级别的权限here
您必须登录、更改您的权限并重新生成您的 api 密钥才能使其正常工作
祝你好运