gpt4 book ai didi

c# - NativeApplicationClient 不受任何支持

转载 作者:行者123 更新时间:2023-11-30 12:09:52 26 4
gpt4 key购买 nike

在我的 Visual Stuidio Win 窗体项目中使用此代码时。

var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret);

我收到一条消息

NativeApplicationClient is not supported any more and it's going to be removed in 1.7.0-beta. Consider using the new Google.Apis.Auth NuGet package which supports .NET 4, .NET for Windows Store apps, Windows Phone 7.5 and 8 and Portable Class Libraries as well

我正在使用

install-package Google.Apis.Authentication -pre

如果我添加 Google.apis.auth 而不是 Google.Apis.Authentication 它甚至没有 NativeApplicationClient。但是我找不到任何关于我应该使用 NativeApplicationClient 的信息。

最佳答案

是的,我让它工作了。

在你的项目中安装这些包

pm> install-package google.apis -pre
pm> install-package google.apis.drive.v2 -pre

添加这些用法

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using System.IO;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;
using System.Threading;

private void Form1_Load(object sender, EventArgs e)
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open,
FileAccess.Read)) {
GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { DriveService.Scope.Drive,
DriveService.Scope.DriveFile },
"user",
CancellationToken.None,
new FileDataStore("Drive.Auth.Store")).Result;
}

对于谷歌驱动器,我会创建一个驱动器服务。您发送针对该服务的所有调用。对谷歌分析同样适用。

BaseClientService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});

我在一篇博文中对此进行了解释:http://daimto.com/google-oauth2-csharp/

如果您弄清楚如何向它提供存储的 refrshToken 并使用它,请告诉我,我仍在努力弄清楚。

关于c# - NativeApplicationClient 不受任何支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19977864/

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