Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

errorStreamInactive when changing broadcast status to live in golang

$
0
0

I am trying to generate a Youtube RTMP url so that I can return it to my client (android) and it can stream using camera.

Taking reference from this python snippet, I tried converting it in Golang like below -

import "google.golang.org/api/youtube/v3"// more importsfunc getUrl(token string) ([]byte, error) {    s := Source{T: token} // google oauth2 token    service, err := youtube.NewService(ctx, option.WithTokenSource(&s))    helper.PanicOnError(err)    liveBroadcast := &youtube.LiveBroadcast{        ContentDetails: &youtube.LiveBroadcastContentDetails{            EnableAutoStart: true,        },        Snippet: &youtube.LiveBroadcastSnippet{            Title: "my first broadcast",            ScheduledStartTime: st,        },        Status: &youtube.LiveBroadcastStatus{            PrivacyStatus: "public",        },    }    liveBroadcast, err = service.LiveBroadcasts.Insert([]string{"snippet", "status", "contentDetails"}, liveBroadcast).Do()    helper.PanicOnError(err)    fmt.Println(liveBroadcast.Id)  // output -> aZSdcfXXXX    liveStream := &youtube.LiveStream{        Snippet: &youtube.LiveStreamSnippet{            Title: "my first stream",        },        Cdn: &youtube.CdnSettings{            Resolution: "720p",            IngestionType: "rtmp",            FrameRate: "30fps",        },        Status: &youtube.LiveStreamStatus{            StreamStatus: "active",        },    }    liveStream, err = service.LiveStreams.Insert([]string{"snippet", "cdn", "status"}, liveStream).Do()    helper.PanicOnError(err)    addr := liveStream.Cdn.IngestionInfo.IngestionAddress +"/" + liveStream.Cdn.IngestionInfo.StreamName    fmt.Println(addr)   // output -> rtmp://a.rtmp.youtube.com/live2/XXXX-XXXX    fmt.Println(liveStream.Status.StreamStatus) // output -> ready    liveBroadcast, err = service.LiveBroadcasts.Bind(liveBroadcast.Id, []string{"id", "contentDetails", "status"}).Do()    helper.PanicOnError(err)    fmt.Println(liveBroadcast.Status.LifeCycleStatus)  // output -> created    fmt.Println(liveStream.Status.StreamStatus)   // output -> ready    liveStream.Status.StreamStatus = "active"    liveStream, err = service.LiveStreams.Update([]string{"snippet", "cdn", "status"}, liveStream).Do()    helper.PanicOnError(err)    fmt.Println(liveStream.Status.StreamStatus)      // output -> ready    liveBroadcast, err = service.LiveBroadcasts.Transition("live", liveBroadcast.Id, []string{"id", "snippet", "contentDetails", "status"}).Do()    helper.PanicOnError(err)     // error ->  googleapi: Error 403: Stream is inactive, errorStreamInactive    fmt.Println("running...")    return nil, nil} 

I can see on Youtube Studio that my broadcast has been created but stream status on Studio console is always "No Data" even though I am streaming using the rtmp ingestion url that I got by calling service.LiveStream.Insert(...)

And at last when I am transition my broadcast to live, I get the following error -

googleapi: Error 403: Stream is inactive, errorStreamInactive

Any ideas what I might be doing wrong?

Thanks


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>