问题描述
当我尝试运行此代码时,它只是继续加载而不向控制台返回任何内容。我认为正在接收数据,但我不确定为什么它不会返回任何内容
import logging
import os
from tweepy import Stream
tweet_count = 0
# Input number of tweets to be downloaded
n_tweets = 2
consumer_key = os.environ['TWITTER_API_KEY']
consumer_secret = os.environ['TWITTER_SECRET_KEY']
oauth_access_token = os.environ['TWITTER_ACCESS_TOKEN']
oauth_access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET']
class MyStreamListener(StreamListener):
def __init__(self,api):
self.api = api
super(StreamListener,self).__init__()
def on_data(self,data):
global tweet_count
global n_tweets
global stream
if tweet_count < n_tweets:
print(data)
tweet_count += 1
return True
else:
stream.disconnect()
def on_error(self,status):
logger.error(status)
def main(keywords,user_id):
api = create_api() # a function to connect to twitter
tweets_listener = MyStreamListener(api)
stream = Stream(api.auth,tweets_listener)
with open("./pages/tweepy.json","w") as outfile:
outfile.write(stream)
if __name__ == "__main__":
main(["Twitter"],["783214"])
它也没有返回任何错误消息。请帮忙。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)