Home > Backend Development > PHP Tutorial > Introduction to the Instagram API

Introduction to the Instagram API

Jennifer Aniston
Release: 2025-03-02 09:32:09
Original
601 people have browsed it

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.

As a developer building an app that requires information from a user's authorized Instagram account, your choice of the two APIs depends on the scope of information you want regarding the user.

If you just want basic profile information about the user or a collection of the media (photos, videos, and albums) on their account, then the Basic Display API will suffice.

However, if you want to get more intricate social media interactions data, metrics, and insights about Instagram Businesses and Creator accounts, then you'll require the Instagram Graph API.

In this tutorial, you'll learn about the Instagram developer API. I'll give you a broad overview of what you can do with both sets of APIs and how to get started.

Before You Begin

To make use of the Instagram API, you'll need to first create and configure an OAuth app in the App dashboard on your Facebook developer account. This process should result in you getting an API access token, which you'll use in every request to the API.

Please keep in mind that there are two different guides for setting things up:

  • If you want permission to call the Instagram Graph API with your app, follow this guide.
  • If you want permission to read basic profile information on an Instagram account (aka Instagram Basic Display API), follow this guide instead.

You should also note that your ability to use certain APIs may depend on the permissions you set for each token in the App dashboard. For this reason, I suggest that you first read this article to see which permission is required for which task.

Using the access token from your app, you can query the API with any HTTP client of your choice.

Basic Display API

With the Instagram Basic Display API, you can tell users of your app to grant you permission to get basic profile information, photos, and videos on their Instagram accounts. The API was created for non-Business and non-Creator Instagram users.

The User Endpoint

The User endpoint allows you to look up basic information about an Instagram user based on their User ID. To use this API, your request must include an Instagram User Access Token, and the following permissions must be enabled on your Instagram OAuth app:

  • instagram_graph_user_media (this is required only if you want the user's api-version (optional): The API version, e.g. v14.0 (learn more about versions in the Instagram API documentation). The value must be a string.
  • fields (optional): A comma-delimited list of the fields and edges you want to be returned by the API. If omitted, the default fields will be returned.
  • account_type, media_count, and /me is mapped to caption, media_type, username, permalink, and instagram_graph_user_media permission and returns a single object by its Media ID.

    For example, here's a sample cURL request:

    curl -X GET \<br>  'https://graph.instagram.com/13445686989093505?fields=id,media_type,media_url,username,timestamp&access_token=IGQVJ...'<br>
    Copy after login

    And here's a sample response:

    {<br>  "id": "13445686989093505",<br>  "media_type": "IMAGE",<br>  "media_url": "https://fb-s-b-a.akamaihd.net/...",<br>  "username": "ubahthebuilder"<br>  "timestamp": "2022-07-20T18:10:00+0000"<br>}<br>
    Copy after login

    The Edge Endpoints

    Edges allow you to get additional information about an Instagram user or media. You can request an edge as a path parameter or by using the fields and caption, media_type, username, permalink, and shopping_product_tag_eligibility field for product tagging)

  • instagram_shopping_tag_products (same as the above)

The API also requires the following on the part of the app user you're intending to retrieve information about (Note: This is only needed if you intend to request the api-version (optional): The API version, eg. v14. The value must be a string.

  • fields (optional): A comma-separated list of the fields and edges you want to be returned by the API. If omitted, the default fields will be returned.
  • biography, followers_count, follows_count, name, shopping_product_tag_eligibility, website. The following image describes what each of these fields returns.Introduction to the Instagram API

    For example, here's a sample cURL request from the docs:

    curl -X GET \<br>  'https://graph.facebook.com/v14.0/17841405822304914?fields=biography%2Cid%2Cusername%2Cwebsite&access_token=EAACwX...'<br>
    Copy after login

    And here's the sample response:

    {<br>  "biography": "Dino data crunching app",<br>  "id": "17841405822304914",<br>  "username": "metricsaurus",<br>  "website": "https://www.metricsaurus.com/"<br>}<br>
    Copy after login

    In addition, the IG User endpoint supports various edges which allow the app to get additional information about the Business or Creator account. These edges are described in the following image.

    Introduction to the Instagram API

    To get any of these data, you simply need to include the corresponding Edge as an additional path parameter to the IG User endpoint. For example, the following endpoint gets a collection of media on an IG User:

    GET https://graph.facebook.com/{api-version}/{ig-user-id}/media<br>  ?fields={fields}<br>  &access_token={access-token}<br>
    Copy after login

    Other Endpoints on the Instagram Graph API

    The remaining APIs for working with Business and Creator accounts are:

    • IG Media: This allows you to retrieve information about an Instagram photo, video, or album by the Instagram media ID.
    • IG Hashtag: This allows you to retrieve information about a given Instagram hashtag.
    • IG Hashtag Search: This root edge allows you to get Instagram hashtag IDs.
    • IG Container: This allows you to retrieve information about a media container's publishing status. A media container is used for publishing an Instagram post.
    • IG Comments: This allows you to retrieve comments on a media by the Instagram comment ID. Information returned from the API includes replies to the comment, the like count, and the comment text.

    Note that each of these API endpoints may require different OAuth scope permissions on your Instagram app, support a different combination of fields and edges, or have certain limitations placed on its usage. As such, make sure to read the complete Instagram API documentation for clarity.

    What Platforms Does the Instagram API Support?

    You can access the Instagram API with any platform or programming language using its REST endpoints.

    Most programming languages come with a built-in HTTP Client API or a third-party library for making API requests. Examples are axios (Node.js), Net::HTTP (Ruby), requests (Python), and guzzlehttp/guzzle (PHP).

    What's Next?

    I hope you're intrigued to begin using the Instagram API. To get started, simply create a Facebook developer account, refer to the Getting Started guide for instructions on how to retrieve your API token, and start querying the API!

    More Coding For Social Media Tutorials

    We've seen some Instagram API examples in this article. It's time to

  • The above is the detailed content of Introduction to the Instagram API. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Latest Articles by Author
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template