Get new media users with username instead of user id.

So, I want to use the Instagram API to get information about the last media of a specific user (NOT MY USER). For this, Instagram has the following endpoint:

(GET) https://api.instagram.com/v1/users/{user-id}/media/recent/?access_token=ACCESS-TOKEN

This is a problem because I do not have a user ID (why me, Instagram?). I do have an account username (like most people), for example. @thisisauser.

I read the API docs and I cannot find the endpoint that will give me the user id for a specific account username. I mean, yes, there are:

(GET) https://api.instagram.com/v1/users/search?q=jack&access_token=ACCESS-TOKEN

... but he does not fulfill what I need in order to search for an exact match.

I also checked other threads in Qaru and other websites. However, the proposed alternative solutions are dubious at best.

I am surprised by the fact that all this is really relevant. I mean SURELY is a legal, Instagram approved, accurate and easy way:

  • getting the latest user media by providing an account username (this is what people know about you ... not about sequence numbers) OR
  • Obtaining a user ID using an exact match search without any likely results.

FYI: I am doing this server side using PHP and cURL.

. API, , , . , Instagram .

+4
3

( ), URL-:

https://www.instagram.com/{username}/?__a=1

, , taylorswift:

https://www.instagram.com/taylorswift/?__a=1
+3

API, . , , .

PHP cURL, - :

//this is what was returned by cURL
$response = /*what was returned by the API - see below*/

{
"data": [{
    "username": "jack",
    "first_name": "Jack",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg",
    "id": "66",
    "last_name": "Dorsey"
},
{
    "username": "sammyjack",
    "first_name": "Sammy",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",
    "id": "29648",
    "last_name": "Jack"
},
{
    "username": "jacktiddy",
    "first_name": "Jack",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",
    "id": "13096",
    "last_name": "Tiddy"
}]
}

//username I am looking for
$user = 'jack';

//filter array response to find exact username you are looking for
$filter = array_filter($response,function($userdata) use ($user){
    if($userdata['username'] == $user){
        return $userdata;
    }
  });

//now use ID from filtered array to get media
$url = 'https://api.instagram.com/v1/users/' . $filter['id'] . '/media/recent/?access_token=ACCESS-TOKEN';
0

!!!

:

<html>
<head>
<script src="jquery.js" type="text/javascript" ></script>
<script type="text/javascript">
  $(document).ready(function(){
     $.ajax({
            type: 'GET',
            url: 'https://api.instagram.com/v1/users/self/?access_token=' + window.location.hash.substring(14),
            dataType: 'jsonp'}).done(function(response){
                 var userid = response.data.id; 
            });
  });
</script>
</head>
<body>
</body>
</html>

. , , , :

https://api.instagram.com/v1/users/{user-id}/media/recent/?access_token=ACCESS-TOKEN

, beter. json php.

-1

Source: https://habr.com/ru/post/1677946/


All Articles