How to use Instagram API

Table of Content
Intro

Data365's API for Instagram is a helpful tool that allows you to search publications by hashtag or location and filter obtained results by needed parameters, including language. Using Instagram API, you can gather a lot of Instagram public profile data. Also, you can get a great deal of info from posts. That's why Instagram API especially will come in handy for companies engaged in marketing research and analytics.

Let's have a look at how to use the Instagram API in more detail. In this article, we tell you how POST and GET requests function and to apply them correctly. We also present the callback_url parameter, with which you can get data directly to the user's URL, and tell you about the format of our API responses and what data you can get. Using the detailed example of post search, we will show how to use Instagram API from Data365.co. And at the end, you learn what webhooks are, what they are for, and how our Instagram API provides this function.

Instagram API request

Instagram API by Data365 is based on HTTP — an application layer protocol to communicate over internet resources. Therefore, it has all the key advantages of this type of API — caching, scaling, minimal overhead, and standard error codes. Our Instagram API uses interaction methods such as POST and GET requests.

POST request is a task to update data, i.e., it's a task to add new Instagram data to the Data365 database or update existing data. Billing is charged for POST requests and is counted in mentions.

GET request is a query to Data365 databases to get the data collected after the POST query has been completed. You can send up to 100 GET requests per second. You are not billed for GET requests.

How to make requests to Instagram API?

When creating requests, be sure to specify the element ID for which you want to get data or search, for example, Instagram post ID, profile ID, location ID, hashtag, etc.

In the POST request, you can specify additional parameters that can increase or decrease the amount of data downloaded by personalizing your Instagram API query.
For example, you can specify for what period of time data is needed (parameters from_date and to_date), select an additional download of comments on posts, posts on profiles or by search (parameters load_comments and load_post), set up automatic data updating (parameter auto_update_interval) or send data to user's URL (callback_url parameter), and many others.

In GET requests, you can also specify additional parameters that allow you to filter and sort the received data.

Instagram callback url

Let's paid more attention to the callback_url parameter using. You can specify this parameter directly in the POST request, and after completing the POST request, you will receive a response with data to your identified link.

Please note that if you specify the callback_url parameter, you will not need to send GET requests to check the task status and receive data.

More detail about the functioning of the "callback_url" parameter you can read at https://data365.co/guides/callback-guide.

Get an API response in Instagram JSON

After completing requests, the user receives a response in JSON. JSON has a significant advantage over other formats that explains its popularity. Firstly, it is more compact, which is very important when exchanging data on the Internet. Secondly, JSON is easier to use and much easier to read and write. It was originally created for JavaScript, but many other languages also have libraries that can work with it. Thus JSON is easy to use for data exchange when the client is applying JavaScript though the server is written in Ruby/PHP/Java or any other language.

With our Instagram API, you can fetch Instagram JSON data from a public Instagram profile based on a database of IDs or usernames of the target profiles and Instagram posts. The most popular data we provide include ID, username, biography, profile photo, business category, language, gender, and age recognition by the user's latest photos, etc.

Instagram API example

This example shows how to search for posts on Instagram by hashtag and get all the data on them.

1

You need to send a POST request with the parameters you need, for example:

COPY

https://api.data365.co/v1.1/instagram/tag/bitcoins/update?max_posts_count=100&load_comments=1&max_comments=50&access_token=TOKEN

In this request:,

  • bitcoins – hashtag to search for;
  • max_posts_count=100 – the maximum number of posts with the bitcoins hashtag that will be downloaded;
  • load_comments=1 – enables downloading comments for each post;
  • max_comments=50 – the maximum number of comments for each post that will be downloaded.

Status "accepted" means that your request has been accepted for processing.

Its approximate cost is = 7 + 100 * 5 = 507 mentions. 7 mentions are charged for the search request itself, 100 mentions are the number of posts we expect to receive, 5 is the estimated cost of a post with comments. So 507 is the estimated cost of the request.

However, if there are only 20 posts for your tag and these 20 posts don't have comments, then the cost of such a request will be 7 + 20 * 1 = 27 mentions. Namely, 7 mentions is the cost of creating the search request itself, 20 is the number of posts found, 1 is the cost of a post without comments.

Thus, we charge only for the data that you actually received after creating a POST request.

2

Then you need to send a GET request to check the status of the request created in paragraph 1:

The request status can have 5 options: created, pending, finished, unknown (when the request has not yet been created, does not exist), and fail (the request was not completed due to an error). Usually, the process of the request execution — created → pending → finished, takes about 1–5 minutes. This time can increase depending on the total number of requests and the amount of data in the request. That is, a request to download 100 posts by tag will take about 1 minute, but downloading 1000 posts with comments will take about 5 minutes.

3

When the status of the request form the paragraph 2 is "finished", you need to send a GET request to get data about posts:

In response, you will receive a list of posts that were found by request created in paragraph 1.

4

To get a list of comments for each post, you need to send a separate GET request for each post. This type of request looks like this:

COPY

https://api.data365.co/v1.1/instagram/post/2509278369173225328/comments?access_token=TOKEN
  • 2509278369173225328 is the post ID that was downloaded and for which you want to receive comments.

Instagram webhooks

Webhook is the feature which is available in both official Instagram API and Data365 Instagram API. Webhooks were specially created to simplify messaging about various events – changing settings, adding a new user, deleting a message, etc. With official Instagram webhooks, you can receive real-time notifications. But only if certain conditions are met: the webhooks for Instagram must be configured with a subscription to the appropriate fields; also, the application must be running and granted the appropriate permissions. For example, if the media object is created by a closed account owner, then the official Instagram webhook would not be sent. Also, official Instagram webhooks do not support Reels videos.

With Instagram API by Data365, you also can set up regular receiving of information about new data. You only need to specify the auto_update_interval parameter, which will monitor the emerging new data. And the callback_url parameter, which will send new data to the user's address (URL). For example, with our API, you can get new posts by hashtags or locations you follow, new comments on posts that users leave, etc.
You can see more Instagram API examples on the Resources page.

We can conclude, Data365 Instagram API is a reliable tool that can help you to get lots of public data. We are fully confident it's a great option for your business growth.