If you are a marketer, you must have started using Threads to run your brand. However, compared with Instagram or Facebook, Threads' backend functions are relatively simple. Currently, it does not even provide post data query or download functions, which is very difficult for community operators. , you will face 2 big problems:
- If you want to check the performance of historical posts, you have to click on them one by one.
- To create performance reports, multiple pieces of data need to be manually sorted.
But there is not enough time to deal with other mundane tasks every day, so how can you have time to sort out these tedious data? Therefore, this article will teach you how to use the Threads API provided by Meta to build an automated reporting system yourself. This has the following benefits:
- Completely customizable: only capture the data you really need.
- Time-saving and efficient: Save the trouble of searching for reports and easily grasp accurate data.
Even if Meta provides Threads data analysis tools in the future, once you understand how to connect the data yourself through the API, you can save time searching for reports and only capture the data you want to see.
What is API?
API is like a food delivery platform, and you are a customer ordering food. When you place an order on the food delivery platform, the food delivery platform (API) will communicate your needs to the restaurant (system backend), and the restaurant will prepare the meal (data results ), and then the delivery person (API) will deliver it to you. Therefore, you only need to send the data requirements, and the API will help pull out the data.
Before implementation, first understand what data can be obtained from the Threads API file
Threads API provides rich data analysis capabilities. Before starting the implementation, it is recommended to understand the types of data that can be collected and their definitions. For example, in the Threads Insights API, you can obtain the following common post data:
- Number of views
- Number of interactive replies
- Number of shares
When using the Threads API, please note the following important limitations:
- The reliability of the user data analysis function before June 1, 2024 is not guaranteed.
- Historical data before April 13, 2024 cannot be queried.
- Only accounts with more than 100 fans can use the data analysis function.
First, you need to complete the basic preparatory work
Step 1: Set up the Meta application
Go to Meta for Developers and log in using your Facebook account. If you don't have a developer account yet, you will be guided through the process to complete account registration.
After logging in, create a new application:
- Click the "Create Application" button in the upper right corner of the homepage.
- Fill in the application name (for example: Threads_brand name).
- Fill in your contact email: Use your primary contact email.
- Add a new use case: Select "Access Threads API".
- Select which merchant asset management portfolio you want to link the application to: you can choose a corporate account or choose not to link.
Then, go to the application master:
- Click "Master Control" in the right column to access the Threads API and add the following permissions:
- threads_basic
- threads_manage_insights
- threads_read_replies
- Click "Application Role" in the right column to add a new user: add the Threads account you want to pull data from, and go to "Authorize Website Permissions" in the Threads account.
- Click "Test" in the right column: click "Test Use Case", and open the "Graphics API Test Tool", switch the URL to Threads.net, Generates Threads Access Token, and then click Submit to see if it works normally. Run out the data. If everything is normal, the initial settings have been completed.
Step 2: Obtain Access Token
First understand what Token is?
Token is like an access card. When you want to enter the building, you need to swipe the access card to confirm your identity. When using the API, the Token is your access card. It tells the API that the request comes from an authorized user. , so it needs to be stored well!
Do not pass it on to others or share it online! Token is your "pass". Anyone who gets it can "impersonate" you and use your permissions, such as outputting confidential data, deleting posts, etc.!
What are long-term & short-term Tokens?
- A short-term token is like a short-term access card that allows you to enter a place, but you need to reapply after it expires. It is suitable for temporary use or testing.
- Long-term Token is an access card with a longer period. Its function is the same as short-term Token, but it saves the trouble of frequent updates and is more suitable for scenarios that require long-term operation, such as automated data harvesting.
There are two steps to obtain long-term Token:
1. Obtain short-term Token first
- Obtain the "Application Key" first
- Enter the application dashboard, click "Application Settings" - "Basic Information", scroll down to find the Threads application key field and click "Show". This string of codes is the application key.
- Obtain "Short-term Token" again
- Enter this URL: https://developers.facebook.com/tools/explorer/.
- Select the newly created application from the Meta application on the right.
- Cut the URL on the left into threads.net.
- Click "Generates Threads Access Token". The access token above is the short-term token.
- Fill in the <your application key> and <short-term Token> positions in the following URL with the corresponding content, then paste the complete URL into the browser address bar and execute it, you will see a long-term Token
Note: If the graphics API test has been completed previously in the basic settings, the access token generated at that time is a short-term Token.
https://graph.threads.net/access_token?grant_type=th_exchange_token&client_secret=<your application secret>&access_token=<short-term Token>
2. Exchange short-term Tokens for long-term Tokens
Fill in the short-term Token you just obtained into the <Token obtained on the web page> in the following URL, and paste the complete URL into the browser to execute.
https://graph.threads.net/refresh_access_token?grant_type=th_refresh_token&access_token=<Token just obtained on the web page>
After completion, first write down the entire long-term Token, which will be used when connecting to the API! Again, don’t pass it on to others or share it on the Internet!
Next, complete Threads API concatenation in two steps
Step 1: Use AI to generate the instructions required for Google Apps Script
Taking post data extraction as an example, assume that the ideal process is:
Automatically import Threads data through Google Sheets and select data for a specific date range.
The command can be issued like this (can be modified according to needs):
- Outline requirements:
Help me generate a Google Apps Script command to pull post data for a specific date range from the Threads API. - Data that needs to be imported:
Retrieve the following data from the Threads API: - Post ID
- Post publication time
- Post content
- Number of views
- Number of likes
- Replies
- Number of forwards
- Number of citations
- Number of shares
- The code needs to include the following functions:
- Added front-end execution menu, options include retrieving data.
- After the user enters the date range (in the format YYYY/MM/DD - YYYY/MM/DD), the program will filter the posts and retrieve data based on the date range.
- Import data into Google Sheets, including title columns (e.g. post ID, number of views, etc.) and automatically format fields (e.g. number format).
- Parameter settings:
The code must contain the following parameters to ensure smooth execution. - ACCESS_TOKEN: Token used for API verification.
- USER_ID: The user ID of the Threads account.
- SPREADSHEET_ID: The ID of the Google spreadsheet.
- APP_SECRET: API application key.
Step 2: Put the instructions into Google Sheet
- Open "Extensions" in Google Sheets and select App Script, and paste the code provided by ChatGPT.
- Paste the parameters that need to be replaced and save them. Press execute and grant permissions. If you run out the data, you will be successful!
How to replace parameters?
- ACCESS_TOKEN: Fill in the long-term Token you just set.
- USER_ID: Fill in the ID that ran out when testing the graphics API earlier.
- SPREADSHEET_ID: Enter the spreadsheet ID from the Google Sheets URL (https://docs.google.com/spreadsheets/d/<spreadsheet ID>/edit ).
- APP_SECRET: Fill in Meta for Developers, Application Settings->Basic Information->Threads application key.
Unable to add a front-end execution menu normally?
You need to pay attention to how the code after it is turned into a function is displayed. For example, the function of "Add Google Sheets Menu" is "onOpen()". You need to confirm that it is indeed the corresponding function before pressing Execute. Otherwise Will be unable to add successfully!