c# – Google Oauth错误:应至少设置一个客户机密码(已安装或Web)

c# – Google Oauth错误:应至少设置一个客户机密码(已安装或Web),第1张

概述我使用Google的Oauth 2.0,通过我们的服务器将视频上传到Youtube. 我的客户端ID是一个“服务帐户”.我下载了json密钥并将其添加到我的解决方案中. 以下是相关代码: private async Task Run(string filePath) { UserCredential credential; var k 我使用Google的Oauth 2.0,通过我们的服务器将视频上传到Youtube.
我的客户端ID是一个“服务帐户”.我下载了Json密钥并将其添加到我的解决方案中.

以下是相关代码:

private async Task Run(string filePath)        {            UserCredential credential;            var keyUrl = System.Web.httpContext.Current.Server.MapPath("~/content/oauth_key.Json");            using (var stream = new fileStream(keyUrl,fileMode.Open,fileAccess.Read))            {                credential = await GoogleWebAuthorizationbroker.AuthorizeAsync(                    GoogleClIEntSecrets.Load(stream).Secrets,// This OAuth 2.0 access scope allows an application to upload files to the                    // authenticated user's YouTube channel,but doesn't allow other types of access.                    new[] { YouTubeService.Scope.YoutubeUpload },"user",CancellationToken.None                );            }            var youtubeService = new YouTubeService(new BaseClIEntService.Initializer()            {                httpClIEntinitializer = credential,Applicationname = Assembly.GetExecutingAssembly().Getname().name            });

当我运行它,我得到这个错误:至少应该设置一个客户端秘密(已安装或Web).

但是,在我的Json里,没有“客户秘密”:

{  "private_key_ID": "9d98c06b3e730070806dcf8227578efd0ba9989b","private_key": "-----BEGIN PRIVATE KEY-----\nMIICdQIBADANBgkqhk etc,"clIEnt_email": "546239405652-8igo05a5m8cutggehk3rk3hspjfm3t04@developer.gserviceaccount.com","clIEnt_ID": "546239405652-8igo05a5m8cutggehk3rk3hspjfm3t04.apps.Googleusercontent.com","type": "service_account"}

所以我假设我忽略了一些东西.
也许我不能使用“服务帐户”?不知道…

解决方法 不是C#上的专家,但是您似乎试图使用服务帐户来执行OAuth2 Web服务器流程,这不应该起作用.
你可能想要使用 ServiceAccountCredential.
有关不同Google OAuth2流程的更多信息,请参阅 web server,service account等文档. 总结

以上是内存溢出为你收集整理的c# – Google Oauth错误:应至少设置一个客户机密码(已安装或Web)全部内容,希望文章能够帮你解决c# – Google Oauth错误:应至少设置一个客户机密码(已安装或Web)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1258783.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存