tsukumijima / tweepy-authlib

Twitter Web App (Web 版公式クライアント) の内部 API を使い、Tweepy でスクリーンネームとパスワードで認証するためのライブラリ
https://pypi.org/project/tweepy-authlib/
MIT License
168 stars 11 forks source link

CookieSessionHandler() Failed to get guest token #3

Closed tettoki closed 1 year ago

tettoki commented 1 year ago

こんにちは。昨今の事情もあり、このライブラリを使ってみようと思いました。

READMEのUsageのscreen_nameとpasswordのみ変更し、実行したところ以下のエラーが出ました。

Traceback (most recent call last):
  File ".\tweepy_authlib_test.py", line 23, in <module>
    auth_handler = CookieSessionUserHandler(screen_name='hoge', password='fuga')
  File "C:\Users\creep\.pyenv\pyenv-win\versions\3.8.10\lib\site-packages\tweepy_authlib\CookieSessionUserHandler.py", line 146, in __init__
    self._login()
  File "C:\Users\creep\.pyenv\pyenv-win\versions\3.8.10\lib\site-packages\tweepy_authlib\CookieSessionUserHandler.py", line 404, in _login
    guest_token = self._get_guest_token(html_response.text)
  File "C:\Users\creep\.pyenv\pyenv-win\versions\3.8.10\lib\site-packages\tweepy_authlib\CookieSessionUserHandler.py", line 289, in _get_guest_token
    raise tweepy.TweepyException('Failed to get guest token')
tweepy.errors.TweepyException: Failed to get guest token

_get_guest_token()で以下のように書いていたのでhtmlを解析したところ、decodeURIComponentという文字列は見つかりませんでした。

# document.cookie = decodeURIComponent("gt=0000000000000000000; Max-Age=10800; Domain=.twitter.com; Path=/; Secure");
# のようなフォーマットで HTML に埋め込まれているので、正規表現で抽出する

document.cookie="guest_id_marketing= document.cookie="guest_id_ads= document.cookie="personalization_id= の3つはありましたが、関係あるものかも分からず自己解決できなかったためissueを建てさせていただきました。必要な情報があれば教えてください。よろしくお願いします。

tsukumijima commented 1 year ago

調べてみたところ、Twitter の仕様変更により、当該のコードが壊れてしまっていたみたいです。 私は最近使っていなかったのでご報告いただけてとても助かりました!ありがとうございました…!

https://github.com/tsukumijima/tweepy-authlib/commit/d0dbf8bac6583e990b294c3d1960ef0aab2dd54b にて修正済みです。 tweepy-authlib を最新版に更新してみてください。おそらく使えるはずです!

tettoki commented 1 year ago

使えるようになりました。ありがとうございました。