Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Apr 11, 2018
1 parent 1de1f50 commit ee95d7a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions instagram_web_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ def _read_response(response):
res = response.read().decode('utf8')
return res

def generate_request_signature(self, query):
if self.rhx_gis and query.get('query_hash') and query.get('variables'):
m = hashlib.md5()
m.update('{rhx_gis}:{csrf_token}:{ua}:{variables}'.format(
rhx_gis=self.rhx_gis,
ua=self.user_agent,
csrf_token=self.csrftoken,
variables=query.get('variables')
).encode('utf-8'))
return m.hexdigest()

def _make_request(self, url, params=None, headers=None, query=None,
return_response=False, get_method=None):
"""
Expand Down Expand Up @@ -222,16 +233,9 @@ def _make_request(self, url, params=None, headers=None, query=None,
})
if query:
url += ('?' if '?' not in url else '&') + compat_urllib_parse.urlencode(query)
if self.rhx_gis and query.get('query_hash') and query.get('variables'):
graphql_variables = query.get('variables')
m = hashlib.md5()
m.update('{rhx_gis}:{csrf_token}:{ua}:{variables}'.format(
rhx_gis=self.rhx_gis,
ua=self.user_agent,
csrf_token=self.csrftoken,
variables=graphql_variables
).encode('utf-8'))
headers['X-Instagram-GIS'] = m.hexdigest()
sig = self.generate_request_signature(query)
if sig:
headers['X-Instagram-GIS'] = sig

req = compat_urllib_request.Request(url, headers=headers)
if get_method:
Expand Down

0 comments on commit ee95d7a

Please sign in to comment.