Giter Club home page Giter Club logo

x-spaces-api's Introduction

x-spaces-api

Retrieve Spaces information for users on X (formerly known as Twitter).

License

Features

  • 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.

Usage example

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"
}

Limitations

Space Playback

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

Embedding Spaces

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.

Development

Prerequisites

Ensure you have:

  • Node.js installed.
  • A Cloudflare account.
  • A Twitter account (a free account is sufficient).

Setup

Installation

To install the project, follow these steps:

git clone https://github.com/antho31/x-spaces-api
cd x-spaces-api
npm install

X Account authentication

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.

Retrieving required tokens
  1. Sign in Twitter
  2. Press F12 to open developer tools
  3. Navigate to the Application tab.
  4. Under Storage, select Cookies > https://twitter.com.
  5. Copy the value of auth_token and assign it to AUTH_TOKEN.
  6. Copy the value of ct0 and assign it to CSRF.

Cloudflare configuration

  1. Log in using wrangler:
npx wrangler login
  1. Configure secrets for production:
npx wrangler secret put AUTH_TOKEN
npx wrangler secret put CSRF

Testing

First, you should start the development server:

npm run dev

Then, run tests with:

npm run test

Deployment

Deploy the project to Cloudflare Workers:

npm run deploy

Note: Remember to note down the published API endpoint.

License

Licensed under the MIT License. Refer to the LICENSE file for details.

Acknowledgments

x-spaces-api's People

Contributors

antho31 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.