如何解决[TWEEPY]:Tweepy StreamListner 拒绝连接
当我尝试运行此代码时,它只是继续加载而不向控制台返回任何内容。我认为正在接收数据,但我不确定为什么它不会返回任何内容
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 举报,一经查实,本站将立刻删除。