【问题标题】:Using tweepy to get the tweeter data?使用 tweepy 获取高音扬声器数据?
【发布时间】:2018-09-09 23:23:23
【问题描述】:

每个人。我是社交媒体信息挖掘的新手。所以当我运行下面的脚本并得到“401”的结果时我很困惑,我用谷歌搜索了我需要授权。谁能帮帮我,非常感谢。

import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
import json

consumer_key = "XXX"
consumer_secret = " XX"
access_token = "XX"
access_secret = "XX"

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

api = tweepy.API(auth)



def parse(cls, api, raw):
    status = cls.first_parse(api, raw)
    setattr(status, 'json', json.dumps(raw))
    return status


 tweepy.models.Status.first_parse = tweepy.models.Status.parse
 tweepy.models.Status.parse = parse


class MyListener(tweepy.StreamListener):

    def on_data(self, data):
        try:
            with open('FILENAME.json', 'a') as f:
                f.write(data)
               return True
        except BaseException as e:
            print("Error on_data: %s" % str(e))
        return True

    def on_error(self, status):
        print(status)
        return True


twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(track=['#HASHTAG_TO_SEARCH'])

【问题讨论】:

  • 您的密钥和机密信息是否正确?
  • 是的。我已经检查了好几次。在这里我只是出于隐私考虑将它们删除...

标签: python twitter tweepy social-media


【解决方案1】:

我用我自己的密钥和秘密运行了你的代码,它就像魅力一样。您可能必须在 Twitter 的应用程序管理中重新生成您的使用者密钥和秘密,然后重试。

【讨论】:

  • 好的,我试试。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2015-03-15
  • 2020-06-30
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-12
  • 2018-09-23
相关资源
最近更新 更多