Instagram ?__a=1 query: Why do I get login page instead of JSON?

Viewed 2525

Here is a sample url that returns JSON of the instagram user's data: https://www.instagram.com/therock/?__a=1

And it returns JSON like this:

{
   "logging_page_id":"profilePage_232192182",
   "show_suggested_profiles":true,
   "show_follow_dialog":false,
   "graphql":{
      "user":{
         "biography":"founder",
         "blocked_by_viewer":false,
         "business_email":null,
         "restricted_by_viewer":false,
         "country_block":false,
         "external_url":"https://projectrock.online/7ad",
         "external_url_linkshimmed":"https://l.instagram.com/?u=https%3A%2F%2Fprojectrock.online%2F7ad&e=ATMKh6M0eOgq-_jVoR3-xJ0Q2wwVSenYemMoYM0A0nWrW9Y5P7mDXX1dkk2dDLidhEuV1Wees7Z3teLJqp7vB2k&s=1",
         "edge_followed_by":{
            "count":199139001
         },
         "followed_by_viewer":false,
         "edge_follow":{
            "count":406
         },
         "follows_viewer":false,
         "full_name":"therock",
         "has_ar_effects":false

I am working on an ASP.NET Core API and have an endpoint that takes in instagram handle and parses the JSON. It works fine locally, but when I hit the same endpoint on the Azure-deployed API, I get the log in page instead:

<!DOCTYPE html>
<html lang="en" class="no-js not-logged-in client-root">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <title>
Login • Instagram
</title>

        
        <meta name="robots" content="noimageindex, noarchive">
        <meta name="apple-mobile-web-app-status-bar-style" content="default">
        <meta name="mobile-web-app-capable" content="yes">
        <meta name="theme-color" content="#ffffff">
        <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover">
        <link rel="manifest" href="/data/manifest.json">

I tried by using a third party browser-as-service (PhantomJsCloud) but returns the same log in page. I thought it was the CORS policy, but fixing it didn't work, and also setting the cookie returned, but to no avail. I am really lost here, I'd be really thankful if anyone can point to why this is happening. Thank you!

1 Answers

probably instagram don't want you to fetch it like that and has some mechanism to identify that your request is done programmatically. I assume when you call it in the browser it is working. You can try to cypress or puppeteer to still make it work or probably use the official api with tokens etc.

EDIT: okay.. I played a little bit around and could make it somehow work, but not sure how reliable this is:

query_id is some kind of hardcoded thing from instagram, other ids can be found here: https://gist.github.com/Carlos-Henreis/2df27431fa5d7a84b7a5e57ee1bf6ae2#file-query_id-csv

Edit 2: Realized this will only work when your ip is also not detected by instagram or you send a cookie of a logged-in session, otherwise you wont get the ProfilePage but a LoginAndSignupPage instead unfortunately

for more info, see here: https://stackoverflow.com/a/57722553/5195852

Related