使用OAuth2通过YouTube API上传视频时遇401未授权错误求助
Hey there, let's break down this frustrating error you're facing—even with valid OAuth tokens, the youtubeSignupRequired reason points to a specific, easy-to-fix issue.
First, let's restate the error you're seeing for clarity:
{Google.Apis.Requests.RequestErrorUnauthorized [401]Errors [ Message[Unauthorized] Location[Authorization - header] Reason[youtubeSignupRequired] Domain[youtube.header]]}
What's actually going wrong?
This error has nothing to do with your AccessToken/RefreshToken validity or Client ID configuration. It means the Google account linked to your OAuth tokens does not have an active YouTube channel associated with it. The YouTube API requires every account that uploads content to have a properly created and activated YouTube channel—even personal Google accounts need this step completed before they can use upload endpoints.
Step-by-step fixes
- Create/activate your YouTube channel: Log into the Google account tied to your OAuth tokens, head to YouTube, and finish the channel creation flow. You can find the option by clicking your profile icon in the top-right corner of YouTube's homepage. If you already created a channel, double-check that it's not restricted or unactivated.
- Re-authorize your OAuth tokens: Even if your existing tokens aren't expired, re-authenticating your app with the account (after the channel is active) ensures the token is linked to the newly created channel. This refreshes the token's context to include the channel's permissions.
- Verify your OAuth scope: Make sure you requested the correct scope during authorization. For video uploads, you need the
https://www.googleapis.com/auth/youtube.uploadscope. If you missed this during initial setup, your tokens won't have permission to upload videos—even with a valid channel.
Quick test to confirm the fix
You can check if the channel issue is resolved by using your AccessToken to call the YouTube channels.list endpoint with the mine=true parameter. If this returns a valid channel object, your account is ready for uploads. If it still throws the same 401 error, go back and double-check the channel activation step.
Here's a quick code snippet for this test (using your existing credential setup):
var youtubeService = new YouTubeService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Your App Name" }); var channelsRequest = youtubeService.Channels.List("snippet"); channelsRequest.Mine = true; try { var channelsResponse = channelsRequest.Execute(); Console.WriteLine($"Found channel: {channelsResponse.Items[0].Snippet.Title}"); } catch (GoogleApiException ex) { Console.WriteLine($"Error checking channel: {ex.Message}"); }
If this test passes, your original upload code should work once you've confirmed the scope and token are correctly configured.
内容的提问来源于stack exchange,提问作者alan samuel

