Search code examples
iosinstagraminstagram-api

Instagram public media API


Does Instagram API policy allows to use

https://instagram.com/{user-id}/media/

endpoint to fetch latests media from iOS app. We tried to use documented

api.instagram.com/v1/users/{user-id}/media/recent

but it requires access token. By investigating Instagram web app I discovered that it is using endpoint from first link for fetching user's data.


Solution

  • The Instagram web app is not using the link you provided, it is using:

    GET https://instagram.com/{username}/

    And in the response inside a script tag it sets Window._sharedData with all the data including the user's media:

    window._sharedData.entry_data.UserProfile[0].userMedia
    

    I am not sure about the policies, but you may fetch and extract this data without calling the API.

    But, using the API would be easier and the preferred way. As you are going to fetch some public media, you can use a fixed client_id instead of an access_token to avoid authentication:

    Some API only require the use of a client_id. A client_id simply associates your server, script, or program with a specific application. However, other requests require authentication - specifically requests made on behalf of a user. Authenticated requests require an access_token. These tokens are unique to a user and should be stored securely. Access tokens may expire at any time in the future.

    The API call:

    api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client_id}