porjo / youtubeuploader

Scripted uploads to Youtube
Apache License 2.0
759 stars 97 forks source link

how to enable exist video Monetization? #143

Closed feeops closed 1 year ago

feeops commented 1 year ago

I want enable the exist video Monetization.

Core code

var err error

    ctx := context.Background()
    ctx = context.WithValue(ctx, oauth2.HTTPClient, &http.Client{})

    client, err := buildOAuthHTTPClient(ctx, []string{youtube.YoutubeUploadScope,
        youtube.YoutubepartnerScope,
        youtube.YoutubeScope})
    if err != nil {
        log.Fatalf("Error building OAuth client: %v", err)
    }

    service, err := youtube.New(client)
    if err != nil {
        log.Fatalf("Error creating Youtube client: %s", err)
    }

rename := &youtube.Video{
        Id: ID,
        Snippet: &youtube.VideoSnippet{
            Title:           "title",
            CategoryId:      "27", // Education
            Description:     "desc",
            DefaultLanguage: "zh-Hant",
            Tags:            []string{"english"},
        },
        Status: &youtube.VideoStatus{
            Embeddable: true,
            PrivacyStatus: "private"},
        MonetizationDetails: &youtube.VideoMonetizationDetails{
            Access: &youtube.AccessPolicy{
                Allowed: true},
        },
    }

call := service.Videos.Update([]string{"id", "snippet", "status", "monetizationDetails"}, rename)

but return this

Error making YouTube API call: googleapi: Error 403: Access forbidden. The request may not be properly authorized., forbidden

can you help me?

porjo commented 1 year ago

FYI, last time I checked Monetization was not supported by the YoutubeAPI - see #12

That said, your error is about access. Try uploading a video - do you get an access error with that also?

feeops commented 1 year ago

Uploading a video has no error

feeops commented 1 year ago

FYI, last time I checked Monetization was not supported by the YoutubeAPI - see #12

That said, your error is about access. Try uploading a video - do you get an access error with that also?

I saw you created a monetization branch.Does it work?

jorisrobijn commented 1 year ago

Hi, Did you read the mentioned issue? Did you try the monetization branch code? I did at the time. There was a problem, which is explained in the mentioned issue. Maybe things are different now, please try. It would of course be a welcome improvement.