You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于YouTube API .NET示例修改视频描述遇403禁止错误求助

Fixing 403 Forbidden Error When Modifying YouTube Video Descriptions via .NET API

Root Cause

The 403 Forbidden error you're hitting is almost certainly tied to an incorrect OAuth 2.0 scope configuration. The original sample code uses a read-only scope, which only lets you view account data—not modify it. When you try to edit a video's description with this restricted scope, YouTube's API rejects the request outright.

Even though you switched to YoutubeForceSsl, if you didn't clear old cached auth tokens or confirm the scope's permissions, the issue persists.

Step-by-Step Solution

1. Confirm & Update the OAuth Scope

First, make sure you're using a scope that grants write access to video metadata. For editing descriptions, use either:

  • YouTubeService.Scope.Youtube: Full access to the authenticated user's YouTube account (covers all write operations)
  • YouTubeService.Scope.YoutubeForceSsl: SSL-only restricted access that still allows modifying video metadata (safer for production)

Here's the corrected authorization code snippet:

using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        // Use a write-enabled scope
        new[] { YouTubeService.Scope.YoutubeForceSsl },
        "user",
        CancellationToken.None,
        new FileDataStore("YouTube.Auth.Store")
    );
}

2. Clear Cached Auth Tokens

OAuth tokens are cached in the FileDataStore you specified. Old tokens issued with read-only permissions won't work with the new scope, so you need to delete the cache:

  • On Windows: Navigate to %APPDATA%\Roaming and delete the YouTube.Auth.Store folder
  • On macOS/Linux: Go to ~/.config and remove the YouTube.Auth.Store folder

This forces a fresh authorization flow, ensuring you get a token with the correct write permissions.

3. Verify Project & Quota Setup

Double-check these critical details to rule out other 403 triggers:

  • Ensure the YouTube Data API v3 is enabled in your Google Cloud project (check under APIs & Services > Enabled APIs & Services)
  • Confirm you haven't exceeded your API quota (view limits under APIs & Services > Quotas)
  • If your app is in testing mode, make sure the authenticated user is added as a test user in the OAuth consent screen settings

4. Implement the Description Update Correctly

Once your auth is sorted, use this example to update a video's description properly:

var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Your App Name"
});

// Fetch the target video (replace with your video ID)
var video = youtubeService.Videos.List("snippet").SetId("YOUR_VIDEO_ID").Execute().Items.First();

// Update the description
video.Snippet.Description = "Your updated video description text here";

// Send the update request (specify "snippet" since we're modifying that part of the video data)
var updateRequest = youtubeService.Videos.Update(video, "snippet");
updateRequest.Execute();

Common Pitfalls to Avoid

  • Forgetting to re-authenticate after scope changes: Cached tokens retain old permissions, so clearing the cache is mandatory.
  • Using the wrong "part" in the update request: The description lives in the snippet part, so you must include that in the Videos.Update call.
  • Overlooking quota limits: Even with correct scopes, hitting your API quota will also trigger a 403 error.

内容的提问来源于stack exchange,提问作者Vitalis Hommel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:00:16