I was following all begining instructions from https://www.nltk.org/howto/twitter.html My file with keys(app_key, app_secret, oauth_token,oauth_token_secret) contains consumer keys and access tokens. But when i try to run this code
from nltk.twitter import Twitter
tw = Twitter()
tw.tweets(keywords='love, hate', limit=10) #sample from the public stream
i get an error(below). I think i am wrong at using acess tokens as oauth_token but i don`t know where i can find a needed.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_3748/1332530833.py in <module>
1 from nltk.twitter import Twitter
2 tw = Twitter()
----> 3 tw.tweets(keywords='love, hate', limit=10) #sample from the public stream
~\AppData\Local\Programs\Python\Python310\lib\site-packages\nltk\twitter\twitterclient.py in tweets(self, keywords, follow, to_screen, stream, limit, date_limit, lang, repeat, gzip_compress)
400 self.streamer.sample()
401 else:
--> 402 self.streamer.filter(track=keywords, follow=follow, lang=lang)
403 else:
404 self.query.register(handler)
~\AppData\Local\Programs\Python\Python310\lib\site-packages\nltk\twitter\twitterclient.py in filter(self, track, follow, lang)
114 msg = "Please supply a value for 'track', 'follow'"
115 raise ValueError(msg)
--> 116 self.statuses.filter(track=track, follow=follow, lang=lang)
117 except requests.exceptions.ChunkedEncodingError as e:
118 if e is not None:
~\AppData\Local\Programs\Python\Python310\lib\site-packages\twython\streaming\types.py in filter(self, **params)
45 url = 'https://stream.twitter.com/%s/statuses/filter.json' \
46 % self.streamer.api_version
---> 47 self.streamer._request(url, 'POST', params=params)
48
49 def sample(self, **params):
~\AppData\Local\Programs\Python\Python310\lib\site-packages\twython\streaming\api.py in _request(self, url, method, params)
135
136 while self.connected:
--> 137 response = _send(retry_counter)
138
139 for line in response.iter_lines(self.chunk_size):
~\AppData\Local\Programs\Python\Python310\lib\site-packages\twython\streaming\api.py in _send(retry_counter)
124 else:
125 if response.status_code != 200:
--> 126 self.on_error(response.status_code, response.content, response.headers)
127
128 if self.retry_count and \
TypeError: Streamer.on_error() takes 3 positional arguments but 4 were given