Google Oauth错误:至少应设置一个客户端机密(已安装或网络) [英] Google Oauth error: At least one client secrets (Installed or Web) should be set

查看:163
本文介绍了Google Oauth错误:至少应设置一个客户端机密(已安装或网络)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google的Oauth 2.0通过我们的服务器将视频上传到Youtube. 我的客户ID是服务帐户".我下载了json密钥并将其添加到我的解决方案中.

I'm using Google's Oauth 2.0 to upload videos to Youtube via our server. My client ID is a "service account". I downloaded the json key and added it to my solution.

以下是相关代码:

 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).

When I run it, I get this error: At least one client secrets (Installed or Web) should be set.

但是,在我的json中没有客户端机密":

However, in my json there is no "client secret":

{
  "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"
}

所以我想我忽略了一些东西. 也许我不能使用服务帐户"?不知道...

so I assume I overlooked something. Maybe I can't use the "service account" ? don't know...

推荐答案

不是C#专家,但您似乎正在尝试使用服务帐户来执行OAuth2 Web服务器流,但这不起作用. 您可能要使用 ServiceAccountCredential 代替. 有关不同的Google OAuth2流的详细信息,请参阅网络服务器的文档,<一个href ="https://developers.google.com/accounts/docs/OAuth2ServiceAccount" rel ="nofollow">服务帐户,等等.

Not an expert on C# but it looks like you were trying to use the service account to do the OAuth2 web server flow, which shouldn't work. You probably want to use ServiceAccountCredential instead. For more information about different Google OAuth2 flows, please refer to the doc for web server, service account, etc.

这篇关于Google Oauth错误:至少应设置一个客户端机密(已安装或网络)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆