CONTACT US
CONTACT US
PRICING
ABOUT US
PRICING
ABOUT US

How to use Twitter API

Intro
Twitter API from Data365 is a reliable tool that allows you to grab a lot of public data from Twitter. You can search for tweets and profiles using keywords or phrases. Using our Twitter API, you can receive a reliable array of data which is indispensable for analyzing consumer preferences and highlighting trends in social media. So, for companies engaged in marketing research and analytics, the use of Twitter API often is requisite because it provides monitoring and data extraction from the ocean of content produced on Twitter daily.

In this article, we take a closer look at how to use the Twitter API. We examine what Twitter API is; explain how POST and GET requests operate, as well as the Twitter callback_url parameter. We talk about the response format of Twitter API from Data365 and what data can be obtained. Also, we show how to use our Twitter API on the example of tweet search. And at the end, you can find a little bit of information on how to test Twitter API by Data365.co.

Query Twitter API

Data365 Twitter API is stood on HTTP, so the receivers themselves initiate a query to the server, and use POST and GET methods to receive large quantities of data.

POST request is a task to update data, i.e., it's a task to add new Twitter data to the Data365 database or update existing data. Billing is charged for POST requests and is counted in mentions. For example, the cost of requesting data for one tweet is 1 mention, for a profile – 9 mentions, for searching a tweet or profile – 7 mentions. More detailed information about the cost of POST requests in mentions for various data you can find at https://api.data365.co/v1.1/twitter/docs#section/API-mentions-quota.

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 Twitter API?

When creating a Twitter API request to extract data, you should specify an element ID – tweet ID or profile ID. When creating search queries (search for tweets or profiles), you can use keywords, phrases, or hashtags.

Search parameter near allows you to search for tweets and profiles by location or filter results by location. It is the equivalent of the near parameter in the Twitter search request. Another useful setting within helps you also to quest for tweets and profiles in some locations and filter results by the distance from the target location. It should be used in conjunction with near in a request.

Also, with Twitter API by Data365, some others search options to find tweets are available. For example, the search parameter min_faves allows you to filter results by the minimal number of likes. With min_replies you can filter results by the minimal number of replies. min_retweets let you filter results by the minimal number of retweets.
Parameter content_filters can help you to remove some results based on content type.

More detailed information you can find in Data365 Twitter API documentation.

Twitter callback url

We will go over the details using the callback url for Twitter. You can indicate the Twitter callback parameter directly in the POST request. API will make a POST request to this URL when the update process is finished. The request body will contain status and error info along with loaded data and pagination cursors. The callback url for Twitter will be helpful when you like to avoid API polling while waiting for updated data.

Please keep in mind that if you point out 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 find at https://data365.co/guides/callback-guide.

You can also create an update task for the item and choose an interval for which this task will be issued. Twitter API can callback URL whenever the update process has finished through a POST request. This parameter will be handy to monitor items without creating update tasks manually. These auto-update tasks you can retrieve or cancel with /tasks endpoints.

Query Twitter API

Data365 Twitter API is stood on HTTP, so the receivers themselves initiate a query to the server, and use POST and GET methods to receive large quantities of data.

POST request is a task to update data, i.e., it's a task to add new Twitter data to the Data365 database or update existing data. Billing is charged for POST requests and is counted in mentions. For example, the cost of requesting data for one tweet is 1 mention, for a profile – 9 mentions, for searching a tweet or profile – 7 mentions. More detailed information about the cost of POST requests in mentions for various data you can find at https://api.data365.co/v1.1/twitter/
docs#section/API-mentions-quota
.

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 Twitter API?

When creating a Twitter API request to extract data, you should specify an element ID – tweet ID or profile ID. When creating search queries (search for tweets or profiles), you can use keywords, phrases, or hashtags.

Search parameter near allows you to search for tweets and profiles by location or filter results by location. It is the equivalent of the near parameter in the Twitter search request. Another useful setting within helps you also to quest for tweets and profiles in some locations and filter results by the distance from the target location. It should be used in conjunction with near in a request.

Also, with Twitter API by Data365, some others search options to find tweets are available. For example, the search parameter min_faves allows you to filter results by the minimal number of likes. With min_replies you can filter results by the minimal number of replies. min_retweets let you filter results by the minimal number of retweets.
Parameter content_filters can help you to remove some results based on content type.

More detailed information you can find in Data365 Twitter API documentation.

Twitter callback url

We will go over the details using the callback url for Twitter. You can indicate the Twitter callback parameter directly in the POST request. API will make a POST request to this URL when the update process is finished. The request body will contain status and error info along with loaded data and pagination cursors. The callback url for Twitter will be helpful when you like to avoid API polling while waiting for updated data.

Please keep in mind that if you point out 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 find at https://data365.co/guides/callback-guide.

You can also create an update task for the item and choose an interval for which this task will be issued. Twitter API can callback URL whenever the update process has finished through a POST request. This parameter will be handy to monitor items without creating update tasks manually. These auto-update tasks you can retrieve or cancel with /tasks endpoints.

Twitter API response

With Twitter API by Data365, you can get information about tweets and public Twitter profiles. Concerning Twitter profile, we provide such essential data as ID, username, description, profile image, location and external URL (provided by the user), number of followings, followers, friends, tweets (including retweets), likes, media, etc. Also, you can receive a detailed list of tweets for only public tweets.

Using Data365 Twitter API let you get large amounts of tweet data such as author ID, location, and place as well as text, language, and other Twitter entities and engagements. For more detail about what data you can receive with our Twitter API, you should use this link: https://data365.co/data#twitter-data.

It is also worth mentioning that we supply our clients with data in JSON format. We are fully confident that JSON has considerable benefits compearing with other formats. They include compactness, simplicity in using as well as reading and writing, and compatibility with many languages.

Twitter API example

In this example, we will show you how to search for tweets on Twitter by keyword and get their detailed data.
First, you need to send a POST query to search and download tweets to our database:
https://api.data365.co/v1.1/twitter/search/post/update?keywords=covid&from_date=2020-01-01&to_date=2021-01-01&search_type=latest&max_posts=100&access_token={TOKEN}
https://api.data365.co/v1.1/twitter/search/
post/update?keywords=covid&from_date=2020-01-01&to_date=2021-01-01&search_type=latest
&max_posts=100&access_token={TOKEN}
In the request, you can specify all the parameters you need. In our example, we are searching for the keyword covid, for the period from January 1, 2020, to January 1, 2021, the search method is latest (search for latest tweets), and the limit is set for the number of tweets that will be fetched for the search – 100.
Status "accepted" means that your request is taken for handling.

Its approximate cost = 7 + 1 * 100 = 107 mentions. 7 mentions are for the search query itself, 1 is the cost per tweet, and 100 mentions is the number of tweets we expect to receive. So 107 is the estimated cost of the request.
To check the status of the created in paragraph 1 request, you should send a GET query:
https://api.data365.co/v1.1/twitter/search/post/update?keywords=covid&from_date=2020-01-01&to_date=2021-01-01&search_type=latest&access_token={TOKEN}
https://api.data365.co/v1.1/twitter/search/
post/update?keywords=covid&from_date=2020-01-01&to_date=2021-01-01&search_type=latest&access_token={TOKEN}
There are six options for the request status: created, pending, finished, unknown (the request has not yet been generated), failed (the request could not be completed due to an error), and canceled (the request has been annulled). The time of request carrying out process from created to finished depends on the number of requests and the volumes of data in each request and usually takes about 1–5 minutes.
When the status of paragraph 2 of the request form is "finished", you should send a GET query for obtained data about tweets:
https://api.data365.co/v1.1/twitter/search/post/posts?keywords=covid&search_type=latest&max_page_size=100&from_date=2020-01-01&to_date=2021-01-01&order_by=date_desc&access_token={TOKEN}
https://api.data365.co/v1.1/twitter/search/
post/posts?keywords=covid&search_type=latest
&max_page_size=100&from_date=2020-01-01&to_date=2021-01-01&order_by=date_desc&access_token={TOKEN}
We have added the order_by=date_desc parameter to the query, which allows you to sort tweets from newest to oldest. Thus, in the response, you will receive a sorted list of tweets with the data that was found by the original query.

Test Twitter API

All users can test Twitter API from Data365 during a free 14-day trial and appreciate its benefits. But keep in mind that there are some restrictions on the free trial on security grounds. To get access to this free trial, fill out this form https://data365.co/contact. Then Data365 manager will contact you and let you free access to the Twitter API for test purposes.
As a result, we can deduce Data365 Twitter API as a helpful tool to scrape large volumes of data about tweets and profiles.

For your comfort use of our API, we prepare more practical Twitter API examples.

And don't forget to follow the Help articles where we regularly add helpful expert articles about our APIs.
We are sure using the Twitter API by Data365 is a great option to get competitive benefits for developing an effective marketing strategy and lead generation.