gpt4 book ai didi

c# - 谷歌 Oauth 错误 : At least one client secrets (Installed or Web) should be set

转载 作者:可可西里 更新时间:2023-11-01 07:50:38 34 4
gpt4 key购买 nike

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

相关代码如下:

 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
});

当我运行它时,出现此错误:至少应设置一个客户端 secret (已安装或 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"
}

所以我想我忽略了什么。也许我不能使用“服务帐户”?不知道...

最佳答案

使用 json 文件的解决方案非常相似。

这是使用 GoogleCredential 对象创建 VisionService 的示例,该对象通过 ServiceAccountCredentialjson 文件创建。

GoogleCredential credential;
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream)
.CreateScoped(VisionService.Scope.CloudPlatform);
}

var service = new VisionService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "my-app-name",
});

此示例需要两个 NuGet 包:

Google.Apis.Vision.v1  
Google.Apis.Oauth2.v2

关于c# - 谷歌 Oauth 错误 : At least one client secrets (Installed or Web) should be set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28825860/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com