twitter apiの地理情報を指定して情報を抜き取りたいのですが、
テキストを参考にしてスクリプトを入力したところ、この様なエラーが出ました。
初めて遭遇するタイプのエラーで、調べてみましたがよくわかりません
どのような状態なのでしょうか。教えていただきたいです。
>>> 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) ... Traceback (most recent call last): File "C:\Users\Shun\Documents\python\lib\site-packages\twitter\stream.py", line 211, in handle_stream_response handle = urllib_request.urlopen(req,) File "C:\Users\Shun\Documents\python\lib\urllib\request.py", line 222, in urlopen return opener.open(url, data, timeout) File "C:\Users\Shun\Documents\python\lib\urllib\request.py", line 531, in open response = meth(req, response) File "C:\Users\Shun\Documents\python\lib\urllib\request.py", line 640, in http_response response = self.parent.error( File "C:\Users\Shun\Documents\python\lib\urllib\request.py", line 569, in error return self._call_chain(*args) File "C:\Users\Shun\Documents\python\lib\urllib\request.py", line 502, in _call_chain result = func(*args) File "C:\Users\Shun\Documents\python\lib\urllib\request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 401: Authorization Required During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Shun\Documents\python\lib\site-packages\twitter\api.py", line 334, in __call__ return self._handle_response(req, uri, arg_data, _timeout) File "C:\Users\Shun\Documents\python\lib\site-packages\twitter\stream.py", line 286, in _handle_response return handle_stream_response( File "C:\Users\Shun\Documents\python\lib\site-packages\twitter\stream.py", line 213, in handle_stream_response raise TwitterHTTPError(e, uri, 'json', arg_data) twitter.api.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=%5BgxtRnfaP6Gc8hjWBVGAcYxpAZ%5D&oauth_nonce=13315667029978475316&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1597825461&oauth_token=%5B1273157088810872832-L77lHzFDHnQvtGiak9iiSw9uC5KgqV%5D&oauth_version=1.0&oauth_signature=tUuxH8vAb014F%2Blf7wiTeGkWURw%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>
参考にしたテキスト(Twitterの空間分析/桐村喬/20191110)
過去に地理情報無しで抜き取れたタイムラインとそのコード
import tweepy from datetime import timedelta CK = '000' CS = '000' AT = '000' AS = '000' class Listener(tweepy.StreamListener): def on_status(self, status): status.created_at += timedelta(hours=9) print('------------------------------') print(status.text) print("{name}({screen}) {created} via {src}\n".format(name=status.author.name, screen=status.author.screen_name,created=status.created_at, src=status.source)) return True def on_error(self, status_code): print('エラー発生: ' + str(status_code)) return True def on_timeout(self): print('Timeout...') return True auth = tweepy.OAuthHandler(CK, CS) auth.set_access_token(AT, AS) listener = Listener() stream = tweepy.Stream(auth, listener) stream.filter(track = ["プログラミング"]) RT @sunabacoTKMT: 3期の卒業生の方が案件とってきた!! ウレシ( ꈍᴗꈍ) #sunabaco #プログラミング https://t.co/zrLlfbhO5x CARIN@SUNABACO(CarinWaka21) 2020-08-23 16:51:05 via Twitter for iPhone
回答1件
あなたの回答
tips
プレビュー