I try to get data from twitter by using API and tweepy python. After install successfully python and tweepy, a try to get data.. Here is my code
enter code here
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
ckey = 'YIlpVeuTTqjJhWbFj6kmF2ecL'
csecret ='rDUpUgmJF6ZVFYsKGbLW43JXoX35mTzQW7JoPWCQwUh2sBhEaM'
atoken = '3262955994-MwFta8wXh0mjIXatX12BL5Smw2ABZtomMLD782E'
asecret='hcyYCOuBBEsrq3MtBpwI2IQqAqIj4wHpCH0rAODR9C6g6'
class listener(StreamListener):
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
auth = OAuthHandler(ckey,csecret)
auth.set_access_token(atoken,asecret)
twitterStream= Stream(auth,listener())
twitterStream.filter(track=['python', 'javascript', 'ruby'])
When I run it, i had an error:
file 'ex.py' ,line 10
print data
^
IndentationError: expected an indented block
I got this code on the Internet.Thanks
Looks like you indented twice on that line. Instead indent on_data()
the same way as it is done for on_error()
(that is, 4 spaces for one level of indentation).
Seems like you are using uneven indentation, I can see 8 spaces in these lines -
def on_data(self, data):
print data
return True
where as only 4 in line -
def on_error(self, status):
print status
I am guessing you have more code where you are using 4 spaces for one level of indentation.
You should use constant amount of spaces for indentation throughout your code. I would advice you to try changing the indentation of the function to 4 spaces and check if that fixes your issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.