Search code examples
javascriptnode.jsgetinstagraminstagram-api

get instagram public media using new api


I am trying to get the 10 latest instagram photos of a public profile in my nodejs app:

const request = require('request');

const accessToken = '1234567890123456789012345678901234567890';

const url = `https://api.instagram.com/v1/users/1470414259/media/recent/?access_token=${accessToken}&count=10`;

request.get(url, { json: true }, (err, res, body) => {

console.log('print the body: ', body);
});

my attempt is not successful, and i get no results. Could somebody help me get this going?

i am trying to follow the example here : https://www.instagram.com/developer/endpoints/users/#get_users_media_recent

update:

i updated the username to user ID, but i am still getting no response:

{ meta: 
   { code: 400,
     error_type: 'APINotFoundError',
     error_message: 'this user does not exist' } }

update 2:

actually i realize that my access token has some restrictions:

{"meta": {"code": 400, "error_type": "OAuthPermissionsException", "error_message": "This request requires scope=public_content, but this access token is not authorized with this scope. The user must re-authorize your application with scope=public_content to be granted this permissions."}}

why is this happening? i am just trying to get some public profile feeds.

update 3:

is there any other way to bypass these access token permissions and just get the 10 media of a public user?


Solution

  • take a look at the json that this link is returning: https://www.instagram.com/aa/?__a=1

      body.user.media[0] will give you the last photo object
      body.user.media[1] will give you the photo before the last one object
    

    .. and so on.

    what you have to do here is change aa in the url I provided to your desired username.

    ps. you might use some json viewer tools to organize the json if you browser doesn't support that