Skip to content

Commit

Permalink
Merge pull request #13 from fa0311/develop
Browse files Browse the repository at this point in the history
v3.0.2
  • Loading branch information
fa0311 authored Feb 3, 2023
2 parents 02bcad1 + c477093 commit bb5ff83
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 27 deletions.
75 changes: 48 additions & 27 deletions TwitterFrontendFlow/TwitterFrontendFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def __flow_token_check(self):
if self.flow_token == None:
raise Exception("not found token")

def __error_check(self):
if self.content.get("errors"):
raise Exception(self.content["errors"][0]["message"])
def __error_check(self, content):
if content.get("errors"):
raise Exception(content["errors"][0]["message"])

def __method_check(self, method_name):
if self.method_check_bypass:
Expand Down Expand Up @@ -135,9 +135,9 @@ def login_flow(self):
params=params,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def LoginJsInstrumentationSubtask(self):
Expand Down Expand Up @@ -171,9 +171,9 @@ def LoginJsInstrumentationSubtask(self):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def LoginEnterUserIdentifierSSO(self, user_id):
Expand Down Expand Up @@ -202,9 +202,9 @@ def LoginEnterUserIdentifierSSO(self, user_id):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def AccountDuplicationCheck(self):
Expand All @@ -227,9 +227,9 @@ def AccountDuplicationCheck(self):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def LoginEnterAlternateIdentifierSubtask(self, text):
Expand All @@ -250,9 +250,9 @@ def LoginEnterAlternateIdentifierSubtask(self, text):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def LoginEnterPassword(self, password):
Expand All @@ -273,9 +273,9 @@ def LoginEnterPassword(self, password):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def LoginTwoFactorAuthChallenge(self, TwoFactorCode):
Expand All @@ -296,9 +296,32 @@ def LoginTwoFactorAuthChallenge(self, TwoFactorCode):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
return self

def LoginAcid(self, acid):
self.__flow_token_check()
self.__method_check("LoginAcid")
data = {
"flow_token": self.flow_token,
"subtask_inputs": [
{
"subtask_id": "LoginAcid",
"enter_text": {"text": acid, "link": "next_link"},
}
],
}
response = self.session.post(
"https://twitter.com/i/api/1.1/onboarding/task.json",
headers=self.__get_headers(),
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def LoginAcid(self, acid):
Expand Down Expand Up @@ -339,8 +362,8 @@ def get_att(self):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.content = response
self.__error_check()
return self

# ct0の更新 無くても動くっぽい
Expand All @@ -360,9 +383,8 @@ def Viewer(self):
headers=self.__get_headers(),
params=params,
)

self.__error_check(response)
self.content = response
self.__error_check()
return self

def RedirectToPasswordReset(self):
Expand Down Expand Up @@ -396,9 +418,9 @@ def password_reset_flow(self):
params=params,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PwrJsInstrumentationSubtask(self):
Expand Down Expand Up @@ -432,9 +454,9 @@ def PwrJsInstrumentationSubtask(self):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PasswordResetBegin(self, user_id):
Expand All @@ -455,9 +477,9 @@ def PasswordResetBegin(self, user_id):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PasswordResetChooseChallenge(self, choices="0"):
Expand All @@ -481,9 +503,9 @@ def PasswordResetChooseChallenge(self, choices="0"):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PwrKnowledgeChallenge(self, text):
Expand All @@ -504,9 +526,9 @@ def PwrKnowledgeChallenge(self, text):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PasswordResetConfirmChallenge(self, code):
Expand All @@ -527,9 +549,9 @@ def PasswordResetConfirmChallenge(self, code):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PasswordResetNewPassword(self, password):
Expand All @@ -550,9 +572,9 @@ def PasswordResetNewPassword(self, password):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

def PasswordResetSurvey(self, choices="0"):
Expand All @@ -576,9 +598,9 @@ def PasswordResetSurvey(self, choices="0"):
json=data,
proxies=self.proxies,
).json()
self.__error_check(response)
self.flow_token = response.get("flow_token")
self.content = response
self.__error_check()
return self

# ログイン後
Expand Down Expand Up @@ -606,8 +628,8 @@ def CreateTweet(self, tweet_text):
headers=self.__get_headers(),
json=data,
).json()
self.__error_check(response)
self.content = response
self.__error_check()
return self

def FavoriteTweet(self, tweet_id):
Expand All @@ -624,8 +646,8 @@ def FavoriteTweet(self, tweet_id):
headers=self.__get_headers(),
json=data,
).json()
self.__error_check(response)
self.content = response
self.__error_check()
return self

def UnfavoriteTweet(self, tweet_id):
Expand All @@ -642,8 +664,8 @@ def UnfavoriteTweet(self, tweet_id):
headers=self.__get_headers(),
json=data,
).json()
self.__error_check(response)
self.content = response
self.__error_check()
return self

def CreateRetweet(self, tweet_id):
Expand All @@ -661,8 +683,8 @@ def CreateRetweet(self, tweet_id):
headers=self.__get_headers(),
json=data,
).json()
self.__error_check(response)
self.content = response
self.__error_check()
return self

def DeleteRetweet(self, tweet_id):
Expand All @@ -680,11 +702,10 @@ def DeleteRetweet(self, tweet_id):
headers=self.__get_headers(),
json=data,
).json()
self.__error_check(response)
self.content = response
self.__error_check()
return self


# Legacy API v1.1

def friendships_create(self, tweet_id):
Expand Down
40 changes: 40 additions & 0 deletions sample2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from TwitterFrontendFlow.TwitterFrontendFlow import TwitterFrontendFlow

flow = TwitterFrontendFlow()

flow.login_flow()
flow.LoginJsInstrumentationSubtask()

while "LoginSuccessSubtask" not in flow.get_subtask_ids():
try:
if "LoginEnterUserIdentifierSSO" in flow.get_subtask_ids():
print("Telephone number / Email address / User name")
flow.LoginEnterUserIdentifierSSO(input())
elif "LoginEnterAlternateIdentifierSubtask" in flow.get_subtask_ids():
print(flow.content["subtasks"][0]["enter_text"]["primary_text"]["text"])
flow.LoginEnterAlternateIdentifierSubtask(input())
elif "LoginEnterPassword" in flow.get_subtask_ids():
print(flow.content["subtasks"][0]["enter_password"]["primary_text"]["text"])
flow.LoginEnterPassword(input())
elif "AccountDuplicationCheck" in flow.get_subtask_ids():
print("AccountDuplicationCheck")
flow.AccountDuplicationCheck()
elif "LoginTwoFactorAuthChallenge" in flow.get_subtask_ids():
header = flow.content["subtasks"][0]["enter_text"]["header"]
print(header["primary_text"]["text"])
flow.LoginTwoFactorAuthChallenge(input())
elif "LoginAcid" in flow.get_subtask_ids():
header = flow.content["subtasks"][0]["enter_text"]["header"]
print(header["secondary_text"]["text"])
flow.LoginAcid(input())
elif "SuccessExit" in flow.get_subtask_ids():
break
else:
print("Non-supported login methods: " + flow.get_subtask_ids())
exit(1)

except:
print("Error")

print("Success")
flow.SaveCookies("cookie.json")

0 comments on commit bb5ff83

Please sign in to comment.