我只是玩“tweepy”,但它似乎对Python 3.4不起作用。来自github的示例代码(见下文)在Windows 7和Python 2.7.9上运行良好,但出于某种原因,当我在Linux机器上使用与Python 3.4相同的代码时,我只会收到授权错误。其他人有同样的问题吗?!如果有,是否有解决方案?
修改
嗯......我是个白痴。问题实际上与我的系统时钟和不正确的设置硬件时钟有关。我重新调整了一切,这实际上是问题的根源。所以代码工作正常。from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Go to http://apps.twitter.com and create an app.
# The consumer key and secret will be generated for you after
consumer_key=""
consumer_secret=""
# After the step above, you will be redirected to your app's page.
# Create an access token under the the "Your access token" section
access_token=""
access_token_secret=""
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print(data)
return True
def on_error(self, status):
print(status)
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['basketball'])