net google for docs c# .net google-drive-sdk google-admin-sdk

c# - for - Autenticando a Google API con OAuth2



google drive api vb net (1)

Estoy probando el código de ejemplo de Realizar la Delegación de Autoridad de Domain-wide de Google Apps usando C # / .NET y, como en otras muestras que he probado, la parte del código que crea un objeto que usa la variable auth dice que la sintaxis es incorrecta Aquí está el código que tengo:

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 = "<some-id>@developer.gserviceaccount.com"; private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"/path/to/<public_key_fingerprint>-privatekey.p12"; /// <summary> /// Build a Drive service object authorized with the service account /// that acts on behalf of the given user. /// </summary> /// @param userEmail The email of the user. /// <returns>Drive service object.</returns> 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<AssertionFlowClient>(provider, AssertionFlowClient.GetState); return new DriveService(auth); } } }

El error que veo es

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

Esta es la primera vez que escribo una aplicación que usa las API de Google y cualquier ayuda para que funcione será muy apreciada.


Este funciona:

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<AssertionFlowClient>(provider, AssertionFlowClient.GetState); m_service = new DriveService(new BaseClientService.Initializer() { Authenticator = auth });