是否有以下代码在输入后不执行(打印推文)的原因?

Is there a reason why the following code does not execute (print the tweets) after taking input?

所以基本上我想打印一组与用户输入的主题相关的推文,但是当我 运行 输入以下代码后没有任何反应,之后我看不到任何输出。如果您能告诉我原因,我将不胜感激:-)

我尝试重新生成访问令牌密钥,然后再次复制粘贴它,但问题仍然存在

import tweepy
consumerKey = "Sgdz0quGjDDTtGbFAxWQ02E5M"
consumerSecret = "alphanumeric"
accessToken = "980878168180609024-nggEvf3WSLb1IcmmHfoCMhDNvZjbMid"
accessTokenSecret = "alpha numeric"

auth = tweepy.OAuthHandler(consumer_key=consumerKey, 
consumer_secret=consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth)

searchTerm = input("Enter keyword/hashtag to search about : ")
number = int(input("How many tweets do you wanna print :  "))
tweets = tweepy.Cursor(api.search, q=searchTerm, lang= "English").items(number)

for tweet in tweets:
    print(tweet.text)

这是我的控制台在执行后显示的内容

runfile('C:/users/acer/.spyder-py3/temp.py', wdir='C:/users/acer/.spyder-py3')

Enter keyword/hastag to search about : bts

How many tweets do you wanna print :  5

In [14]:

(不打印推文)

您的语言需要 "en"。这有效:

searchTerm = input("Enter keyword/hashtag to search about : ")
number = int(input("How many tweets do you wanna print :  "))

print ("Tweets with ", searchTerm, ": ")

for result in tweepy.Cursor(api.search, q=searchTerm, lang="en").items(number):
  print( result.text)

测试结果运行:


Python 3.7.4(默认,2019 年 7 月 9 日,00:06:43) [GCC 6.3.0 20170516] linux

输入keyword/hashtag搜索:kendrick

您想打印多少条推文:2

与肯德里克的推文:

转发@flwrrb0y:他们:你甚至不能跟着肯德里克·拉马尔跳舞

我: RT @Blaqboimagic:高估 Kendrick 是不可接受的