auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
当我运行这行 tweepy 代码时,我遇到了两个问题。尽管在我找到的文档中,但我收到了代码“Tweepy 没有属性 OAuthHandler”。假设那将是有效的代码。
第二个问题是当我注册我的应用程序时,我没有收到一个consumer_token。我也不太确定如何请求消费者令牌。
导入 tweepy
在您尝试调用它的任何类之前。这听起来像是您遇到的主要问题。
首先,您必须同时获得consumer_token
和consumer_secret
。当您注册该应用程序时,它会为您提供几个字符串,然后您可以将其用于身份验证。是 twitter 为您提供的consumer_token
Consumer Key 字符串,然后consumer_secret
是 twitter 为您提供的 Consumer Secret。
然后,当您打电话时,auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
您必须将 theconsumer_token
和 the都设置consumer_secret
为 twitter 为您提供的字符串。那么这应该工作。