Introduction

This week I had to integrate an Instagram-gallery within a Wordpress-installation. I was using a plugin called Instagram Feed. The only thing you need is obviously an Instagram-account. The plugin supports integrating any Instagram feeds as gallery with a shortcode.

I wanted to integrate feeds from different users, where I only had the usernames, but not the user-id which is needed for fetching these feeds. So I had to find the user-id which matches a certain username. Googling the problem reveals no good documentation, however like a thousand tools, where you can type in a username and will receive the respective user-id. The problem: None of this tools worked. Probably, because Instagram updated their API on June 1st, 2016. So I had to figure it out myself, which I wanna share within this post.

How to find the user-id, if you only know the username?

Check out the Instagram developers' section. There you will find out, that you can get all media a certain user posted by calling the following URL:

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

Here you see, that there is a placeholder: {user-id}. This user-id is a bit hard to find if you only know the username, but the solution is also given within the documentation.

Just open

https://api.instagram.com/v1/users/search?q={username}&access_token=ACCESS-TOKEN

in your browser and you will get a response similar to this:

{
    "data": [{
        "username": "jack",
        "first_name": "Jack",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg",
        "id": "66",
        "last_name": "Dorsey"
    }
}

There you see the id within the response. In this case it is 66.This user-id can now be placed in all other API calls, for example:

https://api.instagram.com/v1/users/66/media/recent/?access_token=ACCESS-TOKEN

Note that you'll need an ACCESS-TOKEN for each request you make against the API. Getting an ACCESS-TOKEN is not that hard either. I'll probably make a post about this, too, which I will link to here, once it's finished.