[instagram] fix login
- use mobile user agent header - update general headers - skip /data/shared_data/ step
This commit is contained in:
@@ -915,31 +915,52 @@ class InstagramGraphqlAPI():
|
|||||||
variables["after"] = extr._update_cursor(info["end_cursor"])
|
variables["after"] = extr._update_cursor(info["end_cursor"])
|
||||||
|
|
||||||
|
|
||||||
@cache(maxage=360*24*3600, keyarg=1)
|
@cache(maxage=90*24*3600, keyarg=1)
|
||||||
def _login_impl(extr, username, password):
|
def _login_impl(extr, username, password):
|
||||||
extr.log.info("Logging in as %s", username)
|
extr.log.info("Logging in as %s", username)
|
||||||
|
|
||||||
url = extr.root + "/accounts/login/"
|
user_agent = ("Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 "
|
||||||
page = extr.request(url).text
|
"(KHTML, like Gecko) Chrome/106.0.5249.79 Mobile "
|
||||||
|
"Safari/537.36 Instagram 255.1.0.17.102")
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"X-Web-Device-Id" : text.extract(page, '"device_id":"', '"')[0],
|
"User-Agent" : user_agent,
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "none",
|
||||||
|
"Sec-Fetch-User": "?1",
|
||||||
|
}
|
||||||
|
url = extr.root + "/accounts/login/"
|
||||||
|
response = extr.request(url, headers=headers)
|
||||||
|
|
||||||
|
extract = text.extract_from(response.text)
|
||||||
|
csrf_token = extract('"csrf_token":"', '"')
|
||||||
|
device_id = extract('"device_id":"', '"')
|
||||||
|
rollout_hash = extract('"rollout_hash":"', '"')
|
||||||
|
|
||||||
|
cset = extr.session.cookies.set
|
||||||
|
cset("csrftoken", csrf_token, domain=extr.cookiedomain)
|
||||||
|
cset("ig_did", device_id, domain=extr.cookiedomain)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"User-Agent" : user_agent,
|
||||||
|
"Accept" : "*/*",
|
||||||
|
"X-CSRFToken" : csrf_token,
|
||||||
|
"X-Instagram-AJAX": rollout_hash,
|
||||||
"X-IG-App-ID" : "936619743392459",
|
"X-IG-App-ID" : "936619743392459",
|
||||||
"X-ASBD-ID" : "437806",
|
"X-ASBD-ID" : "198387",
|
||||||
"X-IG-WWW-Claim" : "0",
|
"X-IG-WWW-Claim" : "0",
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
"Origin" : extr.root,
|
||||||
"Referer" : url,
|
"Referer" : url,
|
||||||
|
"Sec-Fetch-Dest" : "empty",
|
||||||
|
"Sec-Fetch-Mode" : "cors",
|
||||||
|
"Sec-Fetch-Site" : "same-origin",
|
||||||
}
|
}
|
||||||
url = extr.root + "/data/shared_data/"
|
|
||||||
data = extr.request(url, headers=headers).json()
|
|
||||||
|
|
||||||
headers["X-CSRFToken"] = data["config"]["csrf_token"]
|
|
||||||
headers["X-Instagram-AJAX"] = data["rollout_hash"]
|
|
||||||
headers["Origin"] = extr.root
|
|
||||||
data = {
|
data = {
|
||||||
"username" : username,
|
"enc_password" : "#PWD_INSTAGRAM_BROWSER:0:{}:{}".format(
|
||||||
"enc_password" : "#PWD_INSTAGRAM_BROWSER:0:{}:{}".format(
|
|
||||||
int(time.time()), password),
|
int(time.time()), password),
|
||||||
|
"username" : username,
|
||||||
"queryParams" : "{}",
|
"queryParams" : "{}",
|
||||||
"optIntoOneTap" : "false",
|
"optIntoOneTap" : "false",
|
||||||
"stopDeletionNonce" : "",
|
"stopDeletionNonce" : "",
|
||||||
@@ -951,11 +972,8 @@ def _login_impl(extr, username, password):
|
|||||||
if not response.json().get("authenticated"):
|
if not response.json().get("authenticated"):
|
||||||
raise exception.AuthenticationError()
|
raise exception.AuthenticationError()
|
||||||
|
|
||||||
cget = extr.session.cookies.get
|
return {cookie.name: cookie.value
|
||||||
return {
|
for cookie in extr.session.cookies}
|
||||||
name: cget(name)
|
|
||||||
for name in ("sessionid", "mid", "ig_did")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def id_from_shortcode(shortcode):
|
def id_from_shortcode(shortcode):
|
||||||
|
|||||||
Reference in New Issue
Block a user