Instagram ?__a=1 url not working anymore & problems with graphql/query to get data

The query_hash does not change, at least in the past few days. It indicate what TYPE of query it is.

Below listed 4 query types I knew, hope these help.

Load more media under https://www.instagram.com/someone/?__a=1

https://www.instagram.com/graphql/query/?query_hash=472f257a40c653c64c666ce877d59d2b&variables={"id":"93024","first":12,"after":"XXXXXXXX"}

(Instagram blocked the above access since 2018-04-12. You have to remove the __a=1 and extract the JSON inside a block. Look for "window._sharedData" in the HTML)

Load more media under https://www.instagram.com/explore/tags/iphone/?__a=1

https://www.instagram.com/graphql/query/?query_hash=298b92c8d7cad703f7565aa892ede943&variables={"tag_name":"iphone","first":12,"after":"XXXXXXXX"}

Load more media under https://www.instagram.com/explore/locations/703629436462521/?__a=1

https://www.instagram.com/graphql/query/?query_hash=ac38b90f0f3981c42092016a37c59bf7&variables={"id":"703629436462521","first":12,"after":"XXXXXXXX"}

Load more comments for https://www.instagram.com/p/Bf-I2P6grhd/

https://www.instagram.com/graphql/query/?query_hash=33ba35852cb50da46f5b5e889df7d159&variables={"shortcode":"Bf-I2P6grhd","first":20,"after":"XXXXXXXX"}

where XXXXXXXX is the end_cursor from the original request


I just came by the same issue.

Looks like they just changed their private api by removing the max_id. Their website seems to have replaced the old api with the graphql api.

https://www.instagram.com/graphql/query/?query_hash=472f257a40c653c64c666ce877d59d2b&variables={"id":"111","first":12,"after":"xxx"}

  • id: user ID,
  • first: amount of nodes to get,
  • after: the 'end_cursor' you can get from data['user']['edge_owner_to_timeline_media']['page_info']['end_cursor']

use either query_hash or query_id

  • query_hash: 472f257a40c653c64c666ce877d59d2b
  • query_id: 17888483320059182

I have no idea how long that query_id/query_hash will work, it's up to Instagram. They will eventually change it.

Updated 4/8/2018 - Before FB didn't check any cookies, but looks like they added quick validation. Try adding ig_pr=2 to the request cookie, when sending your API. This quick fix works for me. Who knows when FB will change it again.

As long as FB doesn't enforce login for these basic APIs, there always will be an easy workaround.


Translated some of the folks' code to PHP:

<?php
function getPublicInfo($username) {
    $url     = sprintf("https://www.instagram.com/$username");
    $content = file_get_contents($url);
    $content = explode("window._sharedData = ", $content)[1];
    $content = explode(";</script>", $content)[0];
    $data    = json_decode($content, true);
    return $data['entry_data']['ProfilePage'][0];
}

Not sure for how long it's gonna work. For my small project it does the job for now. The result is very similar (if not equal) to the one at the URL: instagram.com/{user}/?__a=1