Skip to content

Instantly share code, notes, and snippets.

@osakanataro
Created August 13, 2021 11:27
Show Gist options
  • Save osakanataro/5ee1b6dfa3d1f12f8c2b4492b1676aa8 to your computer and use it in GitHub Desktop.
Save osakanataro/5ee1b6dfa3d1f12f8c2b4492b1676aa8 to your computer and use it in GitHub Desktop.
twitter spaceの取得方法
twitter spaceの取得方法
まず、twitterの普通のAPIで「https://twitter.com/i/spaces/<spaceID>」を取得
https://twitter.com/i/api/graphql/FJoTSHMVF7fMhGLc2t9cog/AudioSpaceById
にGETアクセスしてJSONレスポンスを取得
パラメータ
variables={
"id":"<spaceID>",
"isMetatagsQuery":false,
"withSuperFollowsUserFields":false,
"withUserResults":true,
"withBirdwatchPivots":false,
"withReactionsMetadata":false,
"withReactionsPerspective":false,
"withSuperFollowsTweetFields":false,
"withScheduledSpaces":true
}
レスポンス内にある下記情報
data -> audioSpace -> metadata に
media_key: "<media ID>"
rest_id: "<spaceID>"
scheduled_start: 1628852433483
started_at: 1628852492965
state: "Running"
title: "<spaceタイトル>"
updated_at: 1628853212142
https://twitter.com/i/api/1.1/live_video_stream/status/<media ID>?client=web&use_syndication_guest_id=false&cookie_set_host=twitter.com
これのレスポンスが
{
"source" : {
"location" : "https://prod-fastly-ap-northeast-1.video.pscp.tv/Transcoding/v1/hls/WocfQN5uJPEOS1mRp2EDn664Eh_YOtXV9WVUe6qeiTtcz1xX9NztTTSGfVJ8Xl7jdWkoH-K5V2hBy2OLryH5gQ/non_transcode/ap-northeast-1/periscope-replay-direct-prod-ap-northeast-1-public/audio-space/dynamic_playlist.m3u8?type=live",
"noRedirectPlaybackUrl" : "https://prod-fastly-ap-northeast-1.video.pscp.tv/Transcoding/v1/hls/WocfQN5uJPEOS1mRp2EDn664Eh_YOtXV9WVUe6qeiTtcz1xX9NztTTSGfVJ8Xl7jdWkoH-K5V2hBy2OLryH5gQ/non_transcode/ap-northeast-1/periscope-replay-direct-prod-ap-northeast-1-public/audio-space/dynamic_playlist.m3u8?type=live",
"status" : "LIVE_PUBLIC",
"streamType" : "HLS"
},
"sessionId" : "1426142697509720069",
"chatToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjg5NDAyOTAsImFtYmlndW91c191c2VyX2lkIjoiZXlKVmMyVnlTV1FpT2lJeFFXMVJlazlpU2tKeFpVdGxJbjA9IiwiYnJvYWRjYXN0X2lkIjoiMU1uR25sTUxBa054TyIsImxvd19sYXRlbmN5Ijp0cnVlLCJyZWFkX29ubHkiOmZhbHNlLCJwYXJ0aWNpcGFudF9pbmRleCI6OTQwOTAzMjgwfQ.E3vnndsLs8QbYkD_kPtF6p2uS3-qktQwrohB1m1JYzc",
"lifecycleToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjg5NDAyOTAsImJyb2FkY2FzdF9pZCI6IjFNbkdubE1MQWtOeE8iLCJjcmVhdGVkIjoxNjI4ODUzODkwLCJpZ25vcmUiOmZhbHNlLCJwYXJ0aWNpcGFudF9pbmRleCI6OTQwOTAzMjgwLCJpc19saXZlIjp0cnVlLCJpc19oaWdobGlnaHRzIjpmYWxzZSwidG9rZW5fdmVyc2lvbiI6MX0._nSURP8VlqjAcUi8x4LALYi_qm7jgMeo37-diYFri_8",
"shareUrl" : "https://twitter.com/i/broadcasts/1MnGnlMLAkNxO",
"chatPermissionType" : "StreamTypeLowLatency"
}
で、location にあるURLをstreamlinkに食わせる