This answer is not directly helping the question but posting because someone might benefit from the answer. As of the current date 12 April 2018, the load more APIs will not work without a Cookie
header set.
Below are some codes for fetching Instagram public APIS
let url = "https://www.instagram.com/explore/";
if (payload.type == 'location') {
url = url + "locations/" + payload.location_id + "/" + payload.location_name + "/?__a=1";
} else if (payload.type == 'hashtag') {
url = url + "tags/" + payload.hashtag + "/?__a=1";
} else { //profile
url = "https://www.instagram.com/" + payload.user_name + "/?__a=1";
}
request(url, function (error, response, body) {
body = JSON.parse(body);
//below are params which are required for load more pagination payload
paginationData = {
has_next_page: body.data.user.edge_owner_to_timeline_media.page_info.has_next_page,
end_cursor: body.data.user.edge_owner_to_timeline_media.page_info.end_cursor
};
//user.edge_owner_to_timeline_media for profile posts,
//hashtag.edge_hashtag_to_media for hashtag posts
//location.edge_location_to_media for location posts
});
and for load more items, I am using:
let url = "https://www.instagram.com/graphql/query/";
if (payload.type == 'location') {
let variables = encodeURIComponent('{"id":"' + payload.pagination.id + '","first":50,"after":"' + payload.pagination.end_cursor + '"}');
url = url + "?query_hash=ac38b90f0f3981c42092016a37c59bf7&query_id=17865274345132052&variables=" + variables;
} else if (payload.type == 'hashtag') {
let variables = encodeURIComponent('{"tag_name":"' + payload.pagination.tag_name + '","first":50,"after":"' + payload.pagination.end_cursor + '"}');
url = url + "?query_hash=298b92c8d7cad703f7565aa892ede943&query_id=17875800862117404&variables=" + variables;
} else { //profile
let variables = encodeURIComponent('{"id":"' + payload.pagination.owner_id + '","first":50,"after":"' + payload.pagination.end_cursor + '"}');
url = url + "?query_hash=472f257a40c653c64c666ce877d59d2b&query_id=17888483320059182&variables=" + variables;
}
let options = {
url: url,
headers: {
Cookie: "Cookie value which i copied from my logged in instagram browser window"
}
};
request(options, function (error, response, body) { });
It seems query_id
is no longer required and query_hash
is sufficient now. I'm not sure though but it seems working without them too for me.