Skip to content

Commit

Permalink
use api for guest_token fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Jan 6, 2022
1 parent 42c5274 commit 34678ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions twspace_dl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .FormatInfo import FormatInfo
from .TwspaceDL import TwspaceDL
from .format_info import FormatInfo
from .twspace_dl import TwspaceDL

__all__ = ["FormatInfo", "TwspaceDL"]
20 changes: 11 additions & 9 deletions twspace_dl/twspace_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ def user_id(user_url: str) -> str:

@staticmethod
def guest_token() -> str:
guest_token = ""
for i in range(5):
response = requests.get("https://twitter.com/").text
guest_token_list = re.findall(r"(?<=gt\=)\d{19}", response)
if len(guest_token_list) != 0:
guest_token = guest_token_list[0]
else:
print(f"trying to get guest token try number:{i}", end="\r")
time.sleep(1)
headers = {
"authorization": (
"Bearer "
"AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs"
"=1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
)
}
response = requests.post(
"https://api.twitter.com/1.1/guest/activate.json", headers=headers
).json()
guest_token = response["guest_token"]
if not guest_token:
raise RuntimeError("No guest token found after five retry")
print()
Expand Down

0 comments on commit 34678ea

Please sign in to comment.