Introduction to the Instagram API
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 loginAnd 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 loginThe 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.

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>
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
