如何找到广播 ID 的流 ID,反之亦然(YouTube 数据 API)?

How to find ID for stream for a broadcast ID or vice-versa (YouTube Data API)?

我想查找与状态为 'ready' 的广播关联的流。我一直在使用此调用查看广播,但没有看到流或我可以用来关联它们的密钥:

curl -H "Authorization: Bearer XXX_AUTH_TOKEN_XXX" "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=status&broadcastStatus=all&maxResults=100"

这会产生:

{
  "kind": "youtube#liveBroadcastListResponse",
  "etag": "LgRz6pjADsE_wIIphSY6n_M3LDE",
  "pageInfo": {
    "totalResults": 39,
    "resultsPerPage": 50
  },
  "items": [
    {
      "kind": "youtube#liveBroadcast",
      "etag": "DC7GxUyFsLEyJorVsv7gl7yBxYY",
      "id": "BRsOTPMIb_s",
      "status": {
        "lifeCycleStatus": "ready",
        "privacyStatus": "public",
        "recordingStatus": "notRecording",
        "madeForKids": false,
        "selfDeclaredMadeForKids": false
      }
    },
     ...
 ]
}

同样,我想知道处于 'inactive' 状态的流是否与现有广播相关联,因此如果需要我可以将其添加到新广播。

curl -H "Authorization: Bearer XXX_AUTH_TOKEN_XXX" "https://www.googleapis.com/youtube/v3/liveStreams?part=snippet,cdn,contentDetails,status&mine=true&maxResults=100"

这会产生:

{
  "kind": "youtube#liveStream",
  "etag": "i3qny6yeyCwtlZkNHB5lgMLGF1I",
  "id": "EFWoMyGEmXWkp7dWPLYdWA1615776388366728",
  "snippet": {
    "publishedAt": "2021-03-15T02:46:29Z",
    "channelId": "XXXXXXXXXXXXXXXXXXXXXXXX",
    "title": "Default stream key",
    "description": "Description for default stream key",
    "isDefaultStream": false
  },
  "cdn": {
    "ingestionType": "rtmp",
    "ingestionInfo": {
      "streamName": "XXXX-XXXX-XXXX-XXXX-XXXX",
      "ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
      "backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1",
      "rtmpsIngestionAddress": "rtmps://a.rtmps.youtube.com/live2",
      "rtmpsBackupIngestionAddress": "rtmps://b.rtmps.youtube.com/live2?backup=1"
    },
    "resolution": "variable",
    "frameRate": "variable"
  },
  "status": {
    "streamStatus": "inactive",
    "healthStatus": {
      "status": "noData"
    }
  },
  "contentDetails": {
    "closedCaptionsIngestionUrl": "http://upload.youtube.com/closedcaption?cid=sdgs-zk2j-grt3-x9jj-d7ks",
    "isReusable": true
  }
}

例如,上面的广播显然与上面的流有关,因为它们是由 YouTube Studio 创建的,作为手动启动流时的默认流。但是,从这两个 JSON 片段中不清楚是什么将它们联系起来。

非常感谢任何关于如何关联它们的想法!

我的错误,将 contentDetails 添加到部分修复了这个问题。

curl -H "Authorization: Bearer XXXX_AUTH_TOKEN_XXXX" "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=status,contentDetails&broadcastStatus=all&maxResults=100"

详情:

    {
      "kind": "youtube#liveBroadcast",
      "etag": "m1O2kGwzs7czUSuB5-hvdWu-Qwc",
      "id": "GYnbNz_baGk",
      "status": {
        "lifeCycleStatus": "complete",
        "privacyStatus": "public",
        "recordingStatus": "recorded",
        "madeForKids": true,
        "selfDeclaredMadeForKids": true
      },
      "contentDetails": {
        "boundStreamId": "EFWoMyGEmXWkp7dWPLYdWA1615776388366728",
        "boundStreamLastUpdateTimeMs": "2021-05-17T19:53:36Z",
        "monitorStream": {
          "enableMonitorStream": true,
          "broadcastStreamDelayMs": 0,
          "embedHtml": "\u003ciframe width=\"425\" height=\"344\" src=\"https://www.youtube.com/embed/XXXXXXXXX?autoplay=1&livemonitor=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen\u003e\u003c/iframe\u003e"
        },
        "enableEmbed": false,
        "enableDvr": true,
        "enableContentEncryption": false,
        "startWithSlate": false,
        "recordFromStart": true,
        "enableClosedCaptions": false,
        "closedCaptionsType": "closedCaptionsDisabled",
        "enableLowLatency": false,
        "latencyPreference": "ultraLow",
        "projection": "rectangular",
        "enableAutoStart": true,
        "enableAutoStop": true
      }
    }