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.
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:
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.
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 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:
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>
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>
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)
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.
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>
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>
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.
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>
The remaining APIs for working with Business and Creator accounts are:
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.
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).
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!
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!