Retrieve Spaces information for users on X (formerly known as Twitter).
- Retrieve information like space id, title, media key, playlist URL (.m3u8), and more from any X creator id.
- Supports pagination through cursor parameter.
- Utilizes internal GraphQL API โ no paid developer account required.
- Built using TypeScript and deployed with Wrangler.
Fetch Spaces information from RadioChadFr
Use creator_id
= 1511552753444741120
# The cursor query parameter is optional.
curl --request GET \
--url 'https://[deployment_url]/spaces/1511552753444741120?cursor=DAABCgABF9wpS1-__9QKAAIX0ePcB1dwwggAAwAAAAIAAA'
{
"data":[
{
"space_id":"1YpJkwXXDrjJj",
"embed":"https://twitter.com/i/spaces/1YpJkwXXDrjJj",
"creator":"Radio Chad",
"title":"QU'EST-CE QUE LE LIBERTARIANISME ?",
"state":"Ended",
"media_key":"28_1713278501330231296",
"playlist":"https://prod-fastly-eu-west-3.video.pscp.tv/Transcoding/v1/hls/LMNE3Jc9cDGtHFBHUDxGGMzy69b1RYZGKNq2k2t1zt5XhCc94U4WBbmC69JmhhRe-O3_51c6hjqUNIcEBK5VnQ/non_transcode/eu-west-3/periscope-replay-direct-prod-eu-west-3-public/audio-space/playlist_16748733499282531558.m3u8?type=replay",
"created_at":1697312400536,
"scheduled_start":1698004847505,
"started_at":1698004806977,
"ended_at":"1698010574755",
"is_space_available_for_replay":true,
"total_replay_watched":92,
"total_live_listeners":90
},
{
"space_id":"1YqxoDYWrVMKv",
"embed":"https://twitter.com/i/spaces/1YqxoDYWrVMKv",
"creator":"Radio Chad",
"title":"JEUX VIDEO, BLOCKCHAIN ET TWITTER DE MERDE",
"state":"Ended",
"media_key":"28_1715463023849246720",
"playlist":"https://prod-fastly-eu-west-3.video.pscp.tv/Transcoding/v1/hls/eXBGros1_pCwuUGqj3naP46crSlLAgHADhIBece0PzXGuXdr0PdwypOT80K59UCxsEZXuRjXJC4tTocOjSMBrQ/non_transcode/eu-west-3/periscope-replay-direct-prod-eu-west-3-public/audio-space/playlist_16748906662865588420.m3u8?type=replay",
"created_at":1697833231287,
"started_at":1697833233210,
"ended_at":"1697837404207",
"is_space_available_for_replay":true,
"total_replay_watched":36,
"total_live_listeners":43
}
],
"cursor":"DAABCgABF9wpS1-__78KAAIXy_S8oVag3wgAAwAAAAIAAA"
}
playlist
is the URL for playing the recorded space. However, a direct playback in browser-based HLS players requires a workaround. While the content can be played locally using software like VLC, you might also use FFmpeg to achieve this. Here is an example to record to an .m4a file using FFmpeg:
ffmpeg -i https://prod-fastly-eu-central-1.video.pscp.tv/Transcoding/v1/hls/WgDZzH3Zrm7SMLCKzf3LxHWKRAWipI65v8tkJtkzUQ4LowXU9ui9hGQMGPekDp6RoNPfWoPDjZroC4V7VuRlLw/non_transcode/eu-central-1/periscope-replay-direct-prod-eu-central-1-public/audio-space/playlist_16748038725661342054.m3u8\?type\=replay -c copy -bsf:a aac_adtstoasc output.m4a
embed
is the suitable URL for embedding within an iframe. However, to view the content, the user needs to be logged into their Twitter account.
Ensure you have:
- Node.js installed.
- A Cloudflare account.
- A Twitter account (a free account is sufficient).
To install the project, follow these steps:
git clone https://github.com/antho31/x-spaces-api
cd x-spaces-api
npm install
Create a .dev.vars
file and provide the following environment variables:
Variable Name | Description | Required |
---|---|---|
AUTH_TOKEN | Twitter Authentication token (auth_token from cookies) |
Yes |
CSRF | Twitter Cross-site request forgery token (ct0 from cookies) |
Yes |
Refer to .dev.example.vars
for an example.
- Sign in Twitter
- Press F12 to open developer tools
- Navigate to the
Application
tab. - Under
Storage
, selectCookies
>https://twitter.com
. - Copy the value of
auth_token
and assign it toAUTH_TOKEN
. - Copy the value of
ct0
and assign it toCSRF
.
- Log in using
wrangler
:
npx wrangler login
- Configure secrets for production:
npx wrangler secret put AUTH_TOKEN
npx wrangler secret put CSRF
First, you should start the development server:
npm run dev
Then, run tests with:
npm run test
Deploy the project to Cloudflare Workers:
npm run deploy
Note: Remember to note down the published API endpoint.
Licensed under the MIT License. Refer to the LICENSE file for details.
- Inspired by twspace-crawler