Youtube API C#错误,无法发表评论?我还应该做什么

Youtube API C#错误,无法发表评论?我还应该做什么,youtube,youtube-api,youtube-data-api,Youtube,Youtube Api,Youtube Data Api,这是我在自己选择的视频中插入评论的代码。 这里怎么了?我从这里的另一个问题中得到了这个代码,并对其进行了一些更改,但是: async Task AddVideoCommentAsync(string commentToAdd, string videoID, YouTubeService youtubeService) { CommentSnippet commentSnippet = new CommentSnippet(); commentSnippe

这是我在自己选择的视频中插入评论的代码。 这里怎么了?我从这里的另一个问题中得到了这个代码,并对其进行了一些更改,但是:

async Task AddVideoCommentAsync(string commentToAdd, string videoID, YouTubeService youtubeService)
    {
        CommentSnippet commentSnippet = new CommentSnippet();
        commentSnippet.TextOriginal = commentToAdd;

        Comment topLevelComment = new Comment();
        topLevelComment.Snippet = commentSnippet;

        CommentThreadSnippet commentThreadSnippet = new CommentThreadSnippet();
        commentThreadSnippet.ChannelId = "UCsK0terzCGmIPAeGmW-i-VA";
        commentThreadSnippet.VideoId = videoID;
        commentThreadSnippet.TopLevelComment = topLevelComment;

        CommentThread commentThread = new CommentThread();
        commentThread.Snippet = commentThreadSnippet;

        
        CommentThreadsResource.InsertRequest insertComment = youtubeService.CommentThreads.Insert(commentThread, "snippet");

        await insertComment.ExecuteAsync();
    }

根据API端点的官方文档,调用它的先决条件如下:

此请求需要至少具有以下作用域之一的授权()

范围
https://www.googleapis.com/auth/youtube.force-ssl


因此,您的
youtubeService
应该通过OAuth 2.0身份验证/授权流中获得的凭据进行初始化,并且这些凭据应该在其作用域中附加了上面指定的凭据。

Hi,我在我的YoutubeService对象中添加了YoutubeService.Scopes.youtubeforcessl。你的意思是
YoutubeService.Scopes.youtubeforcessl
,对吗?是的,我不知道确切的名称lol,已经尝试使用google auth cloud Platforms链接来定义范围。我真的lost@Marvin戈尔尼塞克:但是
YoutubeService.Scopes.YoutubeForceSsl
应该可以工作。如果使用它,会生成什么错误消息?下面是代码,我仍然得到相同的错误:错误:Google.api.Requests.RequestError请求没有足够的身份验证作用域。[403]错误[消息[权限不足]位置[-]原因[权限不足]域[全局]]似乎您的问题不是您的代码,而是您的权限。嗯,可能是的。怎么了?我只是拿了OAuth2的id和钥匙然后用了它们我还能做什么
Error: Google.Apis.Requests.RequestError
Request had insufficient authentication scopes. [403]
Errors [
        Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]```