NativeApplicationClient不受支持

时间:2013-11-14 12:37:33

标签: c# .net google-api google-oauth google-api-dotnet-client

在我的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的内容的信息。

1 个答案:

答案 0 :(得分:3)

是的,我让它运转了。

在项目中安装这些软件包

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并使用它让我知道我仍然试图把它弄清楚。

相关问题