NativeApplicationClient不受支持
在我的Visual Stuidio Win表单项目中使用此代码时。
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret);
我收到了一条消息
不再支持NativeApplicationClient,它将在1.7.0-beta中删除。 考虑使用支持.NET 4,.NET for Windows Store应用程序,Windows Phone 7.5和8以及便携式类库的新Google.Apis.Auth NuGet软件包
我在用
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并使用它让我知道我仍然试图想出这个。