2

Im using the graphql api endpoint to call the endpoint to retrieve a posts information using the function below.

async function getInstagramData(url: string) {
  const postHash = '';
  const postAPI = `https://www.instagram.com/graphql/query/?query_hash=${postHash}&variables=${encodeURIComponent(
    `{"shortcode":"${getShortcode(url)}"}`
  )}`;

  console.log(postAPI);

  try {
    const respone = await axios.get(postAPI);
    const json = await respone.data;
    if (!json.data) return null;
    return json.data['shortcode_media'];
  } catch (error) {
    console.log(error);
    return null;
  }
}

This works fine locally but doesn't work on the server as I get a 401 unauthorized. After looking into the response I found

data: {
    message: 'Please wait a few minutes before you try again.',
    require_login: true,
    status: 'fail'
}

My question would be how I should log into the API. From my understanding, I have two solutions (not sure if any of them are possible)

  1. Call the Login API Endpoint store the cookies that are returned and use them when calling the endpoint above.
  2. Is it possible to use a facebook APP ID in my get request to call the request via my application.
Cartion
  • 149
  • 3
  • 12
  • 1
    It is possible you're either hitting the rate limit or the external IP from your cloud provider that Facebook sees the request coming from is being used by one or more other people causing a rate-limiting error. What if you send the request from your server, but with a proxy instead? If that works and you're sure you're not hitting the rate limit, then it's most likely an issue with your cloud service provider. – AviusX Jan 09 '23 at 18:24
  • 1
    Instagram blocks data centre/cloud provider IPs. My AWS Lambda and Netlify build/function scripts all get these errors too, even when the exact same headers/cookies etc work fine on my local machine/residential IP. – Phil Wolstenholme Jan 16 '23 at 20:12
  • Could you guys solve the problem? – Ahmet Aziz Beşli Aug 15 '23 at 18:20
  • if you want to try and get around instagram blocking data centres/cloud providers you can try and proxy your requests haven't tested it but if they are private proxies it should work. – Cartion Aug 17 '23 at 01:13

0 Answers0