【问题标题】:Is it possible to implement OAuth 2.0 with Google Sites API?是否可以使用 Google Sites API 实现 OAuth 2.0?
【发布时间】:2014-05-22 12:31:23
【问题描述】:

我尝试找到一种使用 OAuth 方法访问 Google Site 网站的方法。今天,我可以通过基本身份验证(Google.GData.Client、用户名/密码)访问我的网站,但我没有找到有关此协议的文档、教程或问题。

我使用 .Net 库和 C# 语言。

有没有可能?

提前致谢,

Azuken

【问题讨论】:

    标签: c# oauth google-api google-sites


    【解决方案1】:

    我建议您尝试 Google 的 Google.Apis.SiteVerification.v1 客户端库。如果您安装 NuGet 包,它将自动安装所有您需要处理的身份验证。

    注意:我不能 100% 确定这是正确的文件。这里有一个客户端库使用的 API 列表Google APIs Client Library for .NET

    我手头上的唯一一个使用 C# 的 Oauth 示例使用的是 Google Drive API,您将不得不对其进行一些更改。

    您需要找到与 Google 网站一起使用的正确范围

    UserCredential credential; 
     credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                  new ClientSecrets { ClientId = "YourClientId", ClientSecret = "YourClientSecret" },
                  new[] { DriveService.Scope.Drive,
                    DriveService.Scope.DriveFile },
                  "user",
                  CancellationToken.None,
                  new FileDataStore("Drive.Auth.Store")).Result; }
    

    一旦您通过身份验证,您只需创建一个服务,您的所有请求都会发送到该服务。这又创建了一个 Google Drive 服务。

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

    很抱歉,我没有针对您正在使用的 API 的代码,但我希望这对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-06-02
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 2015-11-11
      相关资源
      最近更新 更多