【问题标题】:How can I get my Stream Key through YouTube's Live API?如何通过 YouTube 的 Live API 获取我的 Stream Key?
【发布时间】:2025-12-15 12:40:01
【问题描述】:

我使用自己的编码器流式传输视频。当我流式传输时,我必须继续返回 YouTube 以更改选定的流密钥以使用创建的第一个密钥。如何更改或确保 YoutTube API 使用原始流密钥而不生成新密钥。

我尝试过使用列表、更新和转换,但没有任何响应提供流密钥或允许我更改正在使用的流密钥

        title = getStreamTitle();
        System.out.println("You chose " + title + " for stream title.");

        // Create a snippet with the video stream's title.
        LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
        streamSnippet.setTitle(title);




        // Define the content distribution network settings for the
        // video stream. The settings specify the stream's format and
        // ingestion type. See:
        // https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn
        CdnSettings cdnSettings = new CdnSettings();
        cdnSettings.setFormat("1080p");
        cdnSettings.setIngestionType("rtmp");
        cdnSettings.getIngestionInfo();

        LiveStream stream = new LiveStream();
        stream.setKind("youtube#liveStream");
        stream.setSnippet(streamSnippet);
        stream.setCdn(cdnSettings);


        // Construct and execute the API request to insert the stream.
        YouTube.LiveStreams.Insert liveStreamInsert =
                youtube.liveStreams().insert("snippet,cdn", stream);
        LiveStream returnedStream = liveStreamInsert.execute();

这是我目前正在做的,但这会为 YouTube 广播事件创建一个新流。我不希望它创建一个新流,但我需要返回密钥。

private static String getStreamTitle() throws IOException {

    String title = "";

    System.out.print("Please enter a stream title: ");
    BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
    title = bReader.readLine();

    if (title.length() < 1) {
        // Use "New Stream" as the default title.
        title = "New Stream";
    }
    return title;
}

我要么希望输出给我一个流密钥,我可以将它添加到我的编码器中,或者能够直接使它使用以前的流,这样可重用的流密钥保持不变。

【问题讨论】:

    标签: java stream youtube-api youtube-livestreaming-api


    【解决方案1】:

    对于那些没有看过 OP 的新帖子的人,他们在哪里发布了他们的答案,您可以使用以下方式获取流密钥:

    returnedStream.getCdn().getIngestionInfo().getStreamName();
    

    How can I change the stream my event uses via the YouTube live api?

    【讨论】:

    • returnedStream.getCdn().getIngestionInfo().getStreamName();看起来这停止了工作。请建议是否有人使用它。我现在收到异常 com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error { "code" : 500, "errors" : [ { "domain" : "global", "message" : "Internal遇到错误。”,“原因”:“后端错误”}],“消息”:“遇到内部错误。”,“状态”:“内部”}