【问题标题】:NativeApplicationClient is not supported any不支持 NativeApplicationClient 任何
【发布时间】:2013-11-27 11:25:14
【问题描述】:

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

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

我收到一条消息

NativeApplicationClient 不再受支持,它将在 1.7.0-beta 中被删除。考虑使用新的 Google.Apis.Auth NuGet 包,它支持 .NET 4、.NET for Windows Store 应用程序、Windows Phone 7.5 和 8 以及便携式类库

我正在使用

安装包 Google.Apis.Authentication -pre

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

【问题讨论】:

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


    【解决方案1】:

    是的,我让它工作了。

    在你的项目中安装这些包

    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 并使用它,请告诉我我仍在尝试解决这个问题。

    【讨论】:

    • 请问 GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store" 有什么用?
    • 如果您删除文件数据存储 GoogleWebAuthorizationBroker.Folder 将告诉它在哪里存储身份验证。从技术上讲,您不需要两者。
    • 这是一个较新的教程,它比 daimto.com/google-net-filedatastore-demystified 解释得更好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 2020-09-20
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    相关资源
    最近更新 更多