D
D
Denis Bredun2020-10-03 18:31:15
JavaScript
Denis Bredun, 2020-10-03 18:31:15

Instagram API. How and what request do I need to make to get usernames from posts using their IDs?

I have two access tokens:
1. From Instagram Graph API: var fs_access_token which I get after logging in with Facebook;
2. From Instagram Basic Display: var inst_access_token;
So I have a collection of post id's that I get via ig_hashtag_search: I also have 3 posts on my Instagram business account. And I'm trying to get the usernames of all these posts that I have in my collection with a single endpoint:
var posts_ids; //!= null;

for (var u = 0; u < posts_ids.length; u++) {
  fetch("https://graph.instagram.com/" + posts_ids[u] + "?fields=username&access_token=" + inst_access_token).then(function (response) {
  response.text().then(function (text) {
      alert(text); //using Instagram Basic Display
    });
  });
}

But then I get an error from this request:
{
   "error": {
      "message": "Unsupported get request. Object with ID '17884048231750634' does not exist, cannot be loaded due to missing permissions, or does not support this operation",
      "type": "IGApiException",
      "code": 100,
      "error_subcode": 33,
      "fbtrace_id": "AKiycowo9LbwZbKzxOL-EQ9"
   }
}

Fun fact: if I paste the id of one of the posts that I have on my Instagram business account instead of posts_ids [u], it WILL work! SO, what the hell is going on here? This means that I can only get "username data" from the posts I have on my Instagram account, right? Or what?
I was also trying to get usernames from a different endpoint, where of course I used a different access_token that I get after Facebook login (the access_token I used above was the access_token I get after Instagram login; Instagram Graph API - access_token that I get after logging into Facebook):
for (var u = 0; u < posts_ids.length; u++) {
   fetch("https://graph.facebook.com/v8.0/" + posts_ids[u] + "?fields=username&access_token=" + fs_access_token).then(function (response) {
      response.text().then(function (text) {
         alert(text);
      });
   });
}

But then I get the error again from the request:
{
   "error": {
      "message": "Unsupported get request. Object with ID '17884048231750634' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
      "type": "GraphMethodException",
      "code": 100,
      "error_subcode": 33,
      "fbtrace_id": "AhN5o9eopccP4NrQsu8QuaN"
   }
}

And again, an interesting fact: if I paste the id of one of the posts that I have in my Instagram business account instead of posts_ids [u], then it WILL work! I also tried these options:
for (var u = 0; u < posts_ids.length; u++) {
    fetch("https://graph.facebook.com/v8.0/" + posts_ids[u] + "?fields=username&access_token=" + inst_access_token).then(function (response) {
        response.text().then(function (text) {
           alert(text);
        });
    });
}

And
for (var u = 0; u < posts_ids.length; u++) {
    fetch("https://graph.instagram.com/" + posts_ids[u] + "?fields=username&access_token=" + fs_access_token).then(function (response) {
         response.text().then(function (text) {
             alert(text);
         });
    });
}

But then I get this error:
{
   "error": {
      "message": "Invalid OAuth access token.",
      "type": "OAuthException",
      "code": 190,
      "fbtrace_id": "ARVMttFmcIAfwBTPdYcMEfQ"
   }
}

This is most likely because I'm trying to combine an Instagram access token with Facebook technology and a Facebook access token with Instagram technology. So, can you help me find an endpoint in Instagram Basic or Instagram Graph that allows you to get usernames from OTHER users' posts (preferably through the IDs I get with Hashtag Search / Recent_media)? Or could you help me understand how to use this correctly? Because I'm new and may not know some details. Please help me get usernames of posts through their IDs.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2020-10-04
@opium

Open the insta site and look at the requests simply

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question