twttterAPIから緯度経度を指定して情報を取得したいのですが、エラーとなってしまいます
環境にgoogle colaboratoryを使用していますが、for msg in twitter_stream.statuses.filter(**params):の部分に赤線が引かれています。不備があれば教えていただきたいです。
入力したコード↓
pip install twitter from twitter import * auth = OAuth( consumer_key='000', consumer_secret='000', token='000', token_secret='000' ) params = dict() params["locations"] = "-122.75,36.8,-121.75,37.8" twitter_stream = TwitterStream(auth=auth, domain='stream.Twitter.com') for msg in twitter_stream.statuses.filter(**params): print(msg) HTTPError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/twitter/stream.py in handle_stream_response(req, uri, arg_data, block, timeout, heartbeat_timeout) 210 try: --> 211 handle = urllib_request.urlopen(req,) 212 except urllib_error.HTTPError as e: 9 frames /usr/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 222 opener = _opener --> 223 return opener.open(url, data, timeout) 224 /usr/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout) 531 meth = getattr(processor, meth_name) --> 532 response = meth(req, response) 533 /usr/lib/python3.6/urllib/request.py in http_response(self, request, response) 641 response = self.parent.error( --> 642 'http', request, response, code, msg, hdrs) 643 /usr/lib/python3.6/urllib/request.py in error(self, proto, *args) 569 args = (dict, 'default', 'http_error_default') + orig_args --> 570 return self._call_chain(*args) 571 /usr/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 503 func = getattr(handler, meth_name) --> 504 result = func(*args) 505 if result is not None: /usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs) 649 def http_error_default(self, req, fp, code, msg, hdrs): --> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp) 651 HTTPError: HTTP Error 401: Authorization Required During handling of the above exception, another exception occurred: TwitterHTTPError Traceback (most recent call last) <ipython-input-20-da1590de9d34> in <module>() ----> 1 for msg in twitter_stream.statuses.filter(**params): 2 print(msg) /usr/local/lib/python3.6/dist-packages/twitter/api.py in __call__(self, **kwargs) 332 return self._handle_response_with_retry(req, uri, arg_data, _timeout) 333 else: --> 334 return self._handle_response(req, uri, arg_data, _timeout) 335 336 def _handle_response(self, req, uri, arg_data, _timeout=None): /usr/local/lib/python3.6/dist-packages/twitter/stream.py in _handle_response(self, req, uri, arg_data, _timeout) 286 return handle_stream_response( 287 req, uri, arg_data, block, --> 288 _timeout or timeout, heartbeat_timeout) 289 290 TwitterCall.__init__( /usr/local/lib/python3.6/dist-packages/twitter/stream.py in handle_stream_response(req, uri, arg_data, block, timeout, heartbeat_timeout) 211 handle = urllib_request.urlopen(req,) 212 except urllib_error.HTTPError as e: --> 213 raise TwitterHTTPError(e, uri, 'json', arg_data) 214 return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout, heartbeat_timeout)) 215 TwitterHTTPError: Twitter sent status 401 for URL: 1.1/statuses/filter.json using parameters: (locations=-122.75%2C36.8%2C-121.75%2C37.8&oauth_consumer_key=yDwKsirEsQauycgUcq3WiwNDo&oauth_nonce=11818088211377544754&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1599543020&oauth_token=1273157088810872832-Vf8iUoNNPN20fwubUQ4g5NNhhr4Vul&oauth_version=1.0&oauth_signature=ZUi1QUprI1zIA5Xia4Ml9yQAnaU%3D) details: <html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 401 Unauthorized</title> </head> <body> <h2>HTTP ERROR: 401</h2> <p>Problem accessing '/1.1/statuses/filter.json'. Reason: <pre> Unauthorized</pre> </body> </html>
あなたの回答
tips
プレビュー