How to Create a Widget for Meta Threads using Scriptable
This post will be a bit different. I recently started using Meta Threads, and I saw someone complaining that Meta should create a widget for certain stats. I replied, saying it should be possible using the Scriptable app. Long story short, I decided to dive into this rabbit hole and create some widgets for Meta Threads. I’ll be creating two widgets—one for follower counts and profile visitors for today and yesterday, and a second widget to display view counts for the latest post. I’ll be using the Scriptable app to make these, which you can download for free from the iOS App Store.
Step 1: Set Up the Meta App
The first thing to do is go to Meta for Developers and create an app.
Once you’re there, the setup process is mostly “next-next-next.”
Select “I don’t want to connect a business portfolio yet.”
Then, choose “Access the Threads API”.
Enter your app name and email:
Click “Go to Dashboard”.
In the dashboard settings, continue with more “next-next-next.”
First, go to “Access the Threads API” and select “threads_basic” and “threads_manage_insights”—these are the bare minimum permissions needed for this project. If you want to do more, adjust your permissions accordingly.
Then, click “Test Use Cases” (it should automatically show a green tick).
Finally, click “Finish Customization”.
Step 2: Add Roles
Now, go to “App Roles” and then to “Roles”.
Click “Add People” and select “Threads Tester.” Below that, add your own user, as shown in the screenshot:
Now, open the Threads app with that user. Go to Settings > Account > Website Permissions > Invites and accept the invite.
Step 3: Get an Access Token
Now, we need to get a token. Go to the Facebook Developer Explorer.
Select “threads.net” and click “Generate Threads Access Token”.
When the Threads pop-up appears, just click “Continue.”
You’ll now see your token in the “Access Token” field.
Validate that your token works by using the “Access Token Debugger”:
If it shows something similar to the screenshot below, then you’re good to go.
Step 4: Exchange for a Long-Lived Token
Now we need to exchange this short-lived token (which expires in 60 minutes) for a long-lived token that will last two months. Details are here: Long-Lived Tokens.
Run this command:
Since we’re missing THREADS_APP_SECRET
, go to Facebook Apps, select your app, and go to “App Settings” > “Basic”. You’ll see a screen like this:
Click “Show” next to “App Secret”.
Now use this in the curl
command above to get your long-lived token.
Once you have the long-lived token, recheck it using the Access Token Debugger.
Step 5: Start Building the Widgets
The idea is to have two widgets—a “main” widget for followers + visitors and a “secondary” widget for the last post’s view count.
- The main widget will display stats and handle token refresh, saving it in iCloud under the same filename you initially used.
- The secondary widget will use the same token from iCloud but won’t handle token refreshes (assuming the token remains valid). This means you can’t use the secondary widget independently without adjusting the code. You can, however, copy the token refresh code from the main widget to the secondary if needed.
Step 6: Save the Long-Lived Token to iCloud
To store the token, use this one-time Scriptable app code during your initial setup. The main widget code will handle future token refreshes and updates:
Once the token is in iCloud, we’re ready to build the main widget.
Building the Widgets
Documentation from Meta used for the main widget:
Meta Threads Insights Documentation
For the main widget, I’m using the following endpoints for followers and profile visitors:
Followers:
Profile Visitors:
You can find the full code for the main widget here:
The secondary widget checks the latest post, and if a post exists with stats (since reposts have no views), it displays the view count and a snippet of the post. For reposts, it’ll just show 0.
Documentation from Meta for this part is here:
To fetch the latest threads:
Then, retrieve stats for the latest thread:
Here’s the full code for the secondary widget:
And that’s it! After following these steps, you should have a working Threads widget.