I am trying to use twitter streaming API and the language filter. As suggested by the Twitter API manual (https://dev.twitter.com/streaming/overview/request-parameters#language), I put the following ways and none of them work.
filter(track=['keyword'],language=en) # NameError: name 'en' is not defined
filter(track=['keyword'],language='en') # TypeError: filter() got an unexpected keyword argument 'language'
filter(track=['keyword'],language=['en']) # TypeError: filter() got an unexpected keyword argument 'language'
filter(track=['keyword'],lan=en) #TypeError: filter() got an unexpected keyword argument 'lan'
filter(track=['keyword'],lan='en') #TypeError: filter() got an unexpected keyword argument 'lan'
filter(track=['keyword'],lan=['en']) #TypeError: filter() got an unexpected keyword argument 'lan'
I also tried en-US instead of en. Still doesn't work.
Could you any guru enlighten? Thanks! The followings are the full code:
#Import the necessary methods from tweepy library
# The code is modified from the following links
# http://adilmoujahid.com/posts/2014/07/twitter-analytics/
# Streaming API requesting parameters: https://dev.twitter.com/streaming/overview/request-parameters#language
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
#Variables that contains the user credentials to access Twitter API (removed for privacy)
access_token = ""
access_token_secret = ""
consumer_key = ""
consumer_secret = ""
#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
#This handles Twitter authetification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
#This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
stream.filter(track=['abc']) # <= here is the language filter issue
The correct name of the keyword for the
filter()
function is actuallylanguages
(note thes
on the end.) So, your last line should look like this: