- media = self._download_json(
- 'https://www.instagram.com/graphql/query/', uploader_id,
- 'Downloading JSON page %d' % page_num, query={
- 'query_hash': '472f257a40c653c64c666ce877d59d2b',
- 'variables': json.dumps({
- 'id': uploader_id,
- 'first': 100,
- 'after': cursor,
- })
- })['data']['user']['edge_owner_to_timeline_media']
+ variables = json.dumps({
+ 'id': uploader_id,
+ 'first': 12,
+ 'after': cursor,
+ })
+
+ if self._gis_tmpl:
+ gis_tmpls = [self._gis_tmpl]
+ else:
+ gis_tmpls = [
+ '%s' % rhx_gis,
+ '',
+ '%s:%s' % (rhx_gis, csrf_token),
+ '%s:%s:%s' % (rhx_gis, csrf_token, std_headers['User-Agent']),
+ ]
+
+ for gis_tmpl in gis_tmpls:
+ try:
+ media = self._download_json(
+ 'https://www.instagram.com/graphql/query/', uploader_id,
+ 'Downloading JSON page %d' % page_num, headers={
+ 'X-Requested-With': 'XMLHttpRequest',
+ 'X-Instagram-GIS': hashlib.md5(
+ ('%s:%s' % (gis_tmpl, variables)).encode('utf-8')).hexdigest(),
+ }, query={
+ 'query_hash': '42323d64886122307be10013ad2dcc44',
+ 'variables': variables,
+ })['data']['user']['edge_owner_to_timeline_media']
+ self._gis_tmpl = gis_tmpl
+ break
+ except ExtractorError as e:
+ if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
+ if gis_tmpl != gis_tmpls[-1]:
+ continue
+ raise