1

I would like to use the YouTube API to upload videos to a corporate account in a non-interactive program. I was trying to achieve upload without prompting for authentication and authorization (since there is no interactive user). I would appreciate if someone could validate the following assertions:

  1. It is not possible to use Simple API Access to upload videos.

  2. For OAuth, it is not possible to use "Use service accounts to call Google APIs on behalf of your application instead of an end-user." As described in Justin Smith's Blog post. This would have been my desired solution. Here is the code I tried to do this with. It executes, but always returns as "unauthorized" (401):

    public async Task AnnounceAsync(Recording recording)
    {
        const string emailAddress =
            "xxxxxxx.gserviceaccount.com";
    
        const string keyFile = @"C:\Temp\xxxxxxx-privatekey.p12";
    
        var key = new X509Certificate2(keyFile, "notasecret", X509KeyStorageFlags.Exportable);
    
        var client = new AssertionFlowClient(GoogleAuthenticationServer.Description, key)
                            {
                                ServiceAccountId = emailAddress,
                                Scope = YoutubeService.Scopes.Youtube.GetStringValue()
                            };
    
        var auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
    
        var youtube = new YoutubeService(new BaseClientService.Initializer {Authenticator = auth});
    
        var video = new Video
                {
    
    
                    Snippet = new VideoSnippet
                                    {
                                        Title = recording.Title,
                                        Description = recording.Description,
                                        CategoryId = "22"
                                    },
                    Status = new VideoStatus
                                    {
                                        PrivacyStatus = "public",
                                    }
                };
    
        using (var fileStream = new FileStream(recording.Path, FileMode.Open))
        {
            var videosInsertRequest = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*");
    
            videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
            videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
    
            await Task.Run(() => videosInsertRequest.Upload());
        }
    }
    

So, I have concluded that I need to use the "Installed Application" API access methodology to move through the OAuth login process interactively at least once myself, save the refresh token and then use that refresh token in the future to get new access tokens? I know I can make this work, but it seems awkward. Is there any gotchas to be aware of if I go down this road?

Further questions:

  1. Any future support planned to allow Service Account OAuth use with the YouTube API?
  2. Could my program use the "mobile upload" feature to email videos to its YouTube account?

Thanks in advance for your input.

2 Answers 2

1

At the moment you can't use service accounts. From the doc:

https://developers.google.com/youtube/v3/docs/errors

error/unauthorized/youtubeSignupRequired

This error is commonly seen if you try to use the OAuth 2.0 Service Account flow. YouTube does not support Service Accounts, and if you attempt to authenticate using a Service Account, you will get this error.

The YouTube API blog post:

http://apiblog.youtube.com/2011/10/introducing-google-account-support-and.html

introducing Google Account support also discusses the youtubeSignupRequired error in more detail. Although the blog post explains the error for API version 2.1, the meaning of the error is still applicable.

the "mobile upload" feature to email videos seems to work

Sign up to request clarification or add additional context in comments.

Comments

0

Service accounts are a moving target. But you are correct, if you can get a refresh token, then you should be good to go.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.