YouTubeData API v3:'ready' 到 'live' 广播的转换失败,活动流“403 无效转换”

YouTubeData API v3: transition of 'ready' to 'live' broadcast fails with an active stream "403 Invalid Transition"

我试图将一个已经活跃的流添加到一个新的广播中,但无法开始广播。我采取的步骤是。

  1. 创建了一个新的广播。
curl --request POST \
  "https://youtube.googleapis.com/youtube/v3/liveBroadcasts?part=snippet,contentDetails,status" \
  --header "Authorization: Bearer XXX" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data "{'snippet':{'scheduledStartTime':'2021-05-18T17:28:00Z','title':'Tester','description':'descr'},'status':{'privacyStatus':'public','selfDeclaredMadeForKids':false},'contentDetails':{'enableAutoStart':true,'recordFromStart':true,'latencyPreference':'normal','enableAutoStop':false}}"

{
  "kind": "youtube#liveBroadcast",
  "etag": "gyv8ux9AiVL_NuZefS8SGXc3iZQ",
  "id": "z--Lm8b1mU0",
  "snippet": {
    "publishedAt": "2021-05-18T17:27:39Z",
    "channelId": "XXXXXXXXXXXXXXXX",
    "title": "Tester",
    "description": "descr",
      ...
    },
    "scheduledStartTime": "2021-05-18T17:28:00Z",
    "isDefaultBroadcast": false,
    "liveChatId": "KicKGFVDRUZXb015R0VtWFdrcDdkV1BMWWRXQRILei0tTG04YjFtVTA"
  },
  "status": {
    "lifeCycleStatus": "created",
    "privacyStatus": "public",
    "recordingStatus": "notRecording",
    "madeForKids": false,
    "selfDeclaredMadeForKids": false
  },
  "contentDetails": {
    "monitorStream": {
      "enableMonitorStream": true,
      "broadcastStreamDelayMs": 0,
     ...
    },
    "enableEmbed": false,
    "enableDvr": true,
    "enableContentEncryption": false,
    "startWithSlate": false,
    "recordFromStart": true,
    "enableClosedCaptions": false,
    "closedCaptionsType": "closedCaptionsDisabled",
    "enableLowLatency": false,
    "latencyPreference": "normal",
    "projection": "rectangular",
    "enableAutoStart": true,
    "enableAutoStop": false
  }
}
  1. 将已经激活的流绑定到广播。我希望创建的广播中的 enableAutoStart 能够自动启动广播,但它没有。
curl --request POST "https://youtube.googleapis.com/youtube/v3/liveBroadcasts/bind?id=z--Lm8b1mU0&part=snippet,contentDetails,status&streamId=EFWoMyGEmXWkp7dWPLYdWA1615776388366728" --header "Authorization: Bearer XXXXXXXX" --header "Accept: application/json"
{
  "kind": "youtube#liveBroadcast",
  "etag": "L_Q87yK0gMxEM7VZ-aKHCTZ7n8g",
  "id": "z--Lm8b1mU0",
  "snippet": {
    "publishedAt": "2021-05-18T17:27:39Z",
    "channelId": "UCEFWoMyGEmXWkp7dWPLYdWA",
    "title": "Tester",
    "description": "descr",

    },
    "scheduledStartTime": "2021-05-18T17:28:00Z",
    "isDefaultBroadcast": false,
    "liveChatId": "KicKGFVDRUZXb015R0VtWFdrcDdkV1BMWWRXQRILei0tTG04YjFtVTA"
  },
  "status": {
    "lifeCycleStatus": "ready",
    "privacyStatus": "public",
    "recordingStatus": "notRecording",
    "madeForKids": false,
    "selfDeclaredMadeForKids": false
  },
  "contentDetails": {
    "boundStreamId": "EFWoMyGEmXWkp7dWPLYdWA1615776388366728",
    "boundStreamLastUpdateTimeMs": "2021-05-18T16:58:04Z",
    "monitorStream": {
      "enableMonitorStream": true,
      "broadcastStreamDelayMs": 0,
     ...
    },
    "enableEmbed": false,
    "enableDvr": true,
    "enableContentEncryption": false,
    "startWithSlate": false,
    "recordFromStart": true,
    "enableClosedCaptions": false,
    "closedCaptionsType": "closedCaptionsDisabled",
    "enableLowLatency": false,
    "latencyPreference": "normal",
    "projection": "rectangular",
    "enableAutoStart": true,
    "enableAutoStop": false
  }
}
  1. 已尝试将广播转为直播。我也试过过渡到测试,失败并出现同样的错误。
curl --request POST -H "Authorization: Bearer XXXXXX" "https://www.googleapis.com/youtube/v3/liveBroadcasts/transition?part=id,snippet,contentDetails,status&broadcastStatus=live&id=z--Lm8b1mU0"
{
  "error": {
    "code": 403,
    "message": "Invalid transition",
    "errors": [
      {
        "message": "Invalid transition",
        "domain": "youtube.liveBroadcast",
        "reason": "invalidTransition",
        "extendedHelp": "https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/transition#params"
      }
    ]
  }
}
  1. 已验证流仍然有效。
curl "https://youtube.googleapis.com/youtube/v3/liveStreams?part=snippet,cdn,contentDetails,status&id=EFWoMyGEmXWkp7dWPLYdWA1615776388366728" -H "Authorization: Bearer XXXXXXXXXXX" -H "Accept: application/json"
{
  "kind": "youtube#liveStreamListResponse",
  "etag": "ejyo1UhcC8AFCfiY-TxKo4yhwv0",
  "pageInfo": {
    "totalResults": 0,
    "resultsPerPage": 5
  },
  "items": [
    {
      "kind": "youtube#liveStream",
      "etag": "IZNA8olA5tx8tu2fGKPg4ws0YpM",
      "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": "active",
        "healthStatus": {
          "status": "good"
        }
      },
      "contentDetails": {
       ...
        "isReusable": true
      }
    }
  ]
}

关于如何使这项工作的想法?

我想通了。

显然您无法使用 enableAutoStart=true 创建广播,然后添加活动流。似乎 enableAutoStart=true 使广播转换 API 调用失败以将状态更改为测试、直播或完成。

为了让它工作,我停止然后开始发送到流,这导致流转换为非活动状态然后又回到活动状态。转换导致广播开始。

或者,为了在不重新启动流的情况下使其工作,我执行了以下操作:

  1. 使用 enableAutoStart=false 创建广播
  2. 将活动流绑定到广播(如问题中所述)。
  3. 将直播转为测试,然后转为直播。

这似乎工作正常。

如果转换错误消息表明问题出在 enableAutoStart 上就好了。