Instagram JSON response redirecting to login [Discord JS and Heroku]

Viewed 863

I'm making a discord bot, more precisely learning how to. If I run the bot locally on my own computer, it returns the correct json response, with all the profile details and etc, but if I host it on Heroku I get the following error in Heroku logs

2020-06-09T23:47:45.215756+00:00 app[worker.1]: An error occurred: FetchError: invalid json response body at https://www.instagram.com/accounts/login/?next=/gucci/%3F__a%3D1 reason: Unexpected token < in JSON at position 0

if I go to the link in the error: https://www.instagram.com/accounts/login/?next=/gucci/%3F__a%3D1

I'm greeted with the login form. How can I bypass this?

Again, it works perfectly fine if I run the bot in my own computer. It only happens when I host it on Heroku. This is the fetch code.

const igUsername = args[0].toLowerCase();
const url = `http://www.instagram.com/${igUsername}/?__a=1`;
const res = await fetch(url).then(resUrl => resUrl.json()).catch(err => {
   console.log(`An error occurred: ${err}`);
   return message.reply('Something went wrong! If this isn\'t fixed in the next hour, please appeal a complaint in my discord server!');
});
1 Answers

I don't have enough rep to comment but the issue is your server's ip has been flagged they only allow consumer device ips to query it because of limiting

Related