Csharp/C#教程:使用OAuth2向Google API进行身份validation分享


使用OAuth2向Google API进行身份validation

我正在尝试使用C#/ .NET 执行Google Apps域范围的授权委派中的示例代码,并且像我尝试的其他一些示例一样,创建使用auth变量的对象的代码部分表示他们语法错了。 这是我的代码:

using System; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using DotNetOpenAuth.OAuth2; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Drive.v2; using Google.Apis.Util; namespace GoogleAPIDemo { class DriveServiceObject { private const string SERVICE_ACCOUNT_EMAIL = "@developer.gserviceaccount.com"; private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"pathto-privatekey.p12"; ///  /// Build a Drive service object authorized with the service account /// that acts on behalf of the given user. ///  /// @param userEmail The email of the user. /// Drive service object. static DriveService BuildService(String userEmail) { X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable); var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) { ServiceAccountId = SERVICE_ACCOUNT_EMAIL, Scope = DriveService.Scopes.Drive.GetStringValue(), ServiceAccountUser = userEmail, }; var auth = new OAuth2Authenticator(provider, AssertionFlowClient.GetState); return new DriveService(auth); } } } 

我看到的错误是

 (local variable) OAuth2Athenticator auth Error: The best overloaded method match for 'Google.Apis.DriveService.DriveService(Googel.Apis.Services.BaseClientService.Initializer)' has some invalid arguments 

这是我第一次编写一个使用谷歌API的应用程序,任何帮助实现这项工作将不胜感激!

这个工作:

上述就是C#学习教程:使用OAuth2向Google API进行身份validation分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)

  var provider = new AssertionFlowClient( GoogleAuthenticationServer.Description, new X509Certificate2(privateKeyPath, keyPassword, X509KeyStorageFlags.Exportable)) { ServiceAccountId = serviceAccountEmail, Scope = DriveService.Scopes.Drive.GetStringValue(), ServiceAccountUser = driveHolderAccountEmail }; var auth = new OAuth2Authenticator(provider, AssertionFlowClient.GetState); m_service = new DriveService(new BaseClientService.Initializer() { Authenticator = auth }); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ctvol.com/cdevelopment/1022018.html

(0)
上一篇 2022年1月6日
下一篇 2022年1月6日

精彩推荐