~dricottone/container-images

container-images/nitter/guest_accounts/make.py -rw-r--r-- 4.7 KiB
e61b929eDominic Ricottone Okay now really things are updated a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import requests
import base64
username = 'XXXXXXXXXXXX'
password = 'XXXXXXXXXXXX'
TW_CONSUMER_KEY = '3nVuSoBZnx6U4vzUxf5w'
TW_CONSUMER_SECRET = 'Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys'
TW_ANDROID_BASIC_TOKEN = 'Basic {token}'.format(token=base64.b64encode(
    (TW_CONSUMER_KEY + ":" + TW_CONSUMER_SECRET).encode()
).decode())
# print(TW_ANDROID_BASIC_TOKEN)


authentication = None
bearer_token_req = requests.post("https://api.twitter.com/oauth2/token",
	headers={
      'Authorization': TW_ANDROID_BASIC_TOKEN,
      "Content-Type": "application/x-www-form-urlencoded",
    },
	data='grant_type=client_credentials'
).json()
bearer_token = ' '.join(str(x) for x in bearer_token_req.values())
print(bearer_token)

# The bearer token is immutable
# Bearer AAAAAAAAAAAAAAAAAAAAAFXzAwAAAAAAMHCxpeSDG1gLNLghVe8d74hl6k4%3DRUMF4xAQLsbeBhTSRrCiQpJtxoGWeyHrDb5te2jpGskWDFW82F
guest_token = requests.post("https://api.twitter.com/1.1/guest/activate.json", headers={
	'Authorization': bearer_token,
}).json()['guest_token']
print(guest_token)

twitter_header = {
    'Authorization': bearer_token,
    "Content-Type": "application/json",
    "User-Agent":
        "TwitterAndroid/9.95.0-release.0 (29950000-r-0) ONEPLUS+A3010/9 (OnePlus;ONEPLUS+A3010;OnePlus;OnePlus3;0;;1;2016)",
    "X-Twitter-API-Version": '5',
    "X-Twitter-Client": "TwitterAndroid",
    "X-Twitter-Client-Version": "9.95.0-release.0",
    "OS-Version": "28",
    "System-User-Agent":
        "Dalvik/2.1.0 (Linux; U; Android 9; ONEPLUS A3010 Build/PKQ1.181203.001)",
    "X-Twitter-Active-User": "yes",
    "X-Guest-Token": guest_token,
}

session = requests.Session()


task1 = session.post('https://api.twitter.com/1.1/onboarding/task.json',
	params={
		'flow_name': 'login',
		'api_version': '1',
		'known_device_token': '',
		'sim_country_code': 'us'
	},
	json={
		"flow_token": None,
		"input_flow_data": {
			"country_code": None,
			"flow_context": {
				"referrer_context": {
					"referral_details": "utm_source=google-play&utm_medium=organic",
					"referrer_url": ""
				},
				"start_location": {
					"location": "deeplink"
				}
			},
			"requested_variant": None,
			"target_user_id": 0
		}
	},
	headers=twitter_header
)

session.headers['att'] = task1.headers.get('att')
task2 = session.post('https://api.twitter.com/1.1/onboarding/task.json', 
	json={
        "flow_token": task1.json().get('flow_token'),
        "subtask_inputs": [{
                "enter_text": {
                    "suggestion_id": None,
                    "text": username,
                    "link": "next_link"
                },
                "subtask_id": "LoginEnterUserIdentifier"
            }
        ]
    },
	headers=twitter_header
)

task3 = session.post('https://api.twitter.com/1.1/onboarding/task.json', 
	json={
        "flow_token": task2.json().get('flow_token'),
        "subtask_inputs": [{
                "enter_password": {
                    "password": password,
                    "link": "next_link"
                },
                "subtask_id": "LoginEnterPassword"
            }
        ],
    },
	headers=twitter_header
)

task4 = session.post('https://api.twitter.com/1.1/onboarding/task.json', 
	json={
        "flow_token": task3.json().get('flow_token'),
        "subtask_inputs": [{
                "check_logged_in_account": {
                    "link": "AccountDuplicationCheck_false"
                },
                "subtask_id": "AccountDuplicationCheck"
            }
        ]
    },
	headers=twitter_header
).json()

for t4_subtask in task4.get('subtasks', []):
	if 'open_account' in t4_subtask:
		authentication = t4_subtask['open_account']
		break
	elif 'enter_text' in t4_subtask:
		response_text = t4_subtask['enter_text']['hint_text']
		code = input(f'Requesting {response_text}: ')
		task5 = session.post('https://api.twitter.com/1.1/onboarding/task.json', json={
			"flow_token": task4.get('flow_token'),
			"subtask_inputs": [{
				"enter_text": {
					"suggestion_id": None,
					"text": code,
					"link": "next_link"
				},
				"subtask_id": "LoginAcid"
			}]
		}, headers=twitter_header).json()
		print(task5)
		for t5_subtask in task5.get('subtasks', []):
			print(t5_subtask)
			if 'open_account' in t5_subtask:
				authentication = t5_subtask['open_account']


print(authentication)
		
# {
# 	'attribution_event': 'login',
# 	'known_device_token': 'XXXXXXXXXXXXXXXXXXXXXX',
# 	'next_link': {
# 		'link_id': 'next_link',
# 		'link_type': 'subtask',
# 		'subtask_id': 'SuccessExit'
# 	},
# 	'oauth_token': 'XXXXXXXXXXXXXXXXXXXXXX',
# 	'oauth_token_secret': 'XXXXXXXXXXXXXXXXXXXXXX',
# 	'user': {
# 		'id': 'XXXXXXXXXXXXXXXXXXXXXX',
# 		'id_str': 'XXXXXXXXXXXXXXXXXXXXXX',
# 		'name': 'XXXXXXXXXXXXXXXXXXXXXX',
# 		'screen_name': 'XXXXXXXXXXXXXXXXXXXXXX'
# 	}
# }