Note that there are some explanatory texts on larger screens.

plurals
  1. POAssertionFlowClient depreceated, trying to use ServiceAccountCredential, but it won't work
    primarykey
    data
    text
    <p>I've tried creating a DriveService using service account acting on behalf of another user.</p> <p>I've copied this code from google documentation found here <a href="https://developers.google.com/drive/delegation" rel="noreferrer">https://developers.google.com/drive/delegation</a></p> <pre><code> static DriveService BuildService() { 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(), }; var auth = new OAuth2Authenticator&lt;AssertionFlowClient&gt;(provider, AssertionFlowClient.GetState); return new DriveService(auth); } </code></pre> <p>but I get this warning when trying to build the project:</p> <p>Warning 4 'Google.Apis.Authentication.OAuth2.DotNetOpenAuth.AssertionFlowClient' is obsolete: 'AssertionFlowClient is not supported any more and it's going to be removed in 1.7.0-beta. Consider using ServiceAccountCredential from the new Google.Apis.Auth NuGet package.'</p> <p>and I also get this error:</p> <p>Error 11 Argument 1: cannot convert from 'Google.Apis.Authentication.OAuth2.OAuth2Authenticator' to 'Google.Apis.Services.BaseClientService.Initializer'</p> <p>Then I googled ServiceAccountCredential and ended up with this code (derived from this page: <a href="https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Service_Accounts" rel="noreferrer">https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Service_Accounts</a>)</p> <pre><code>static DriveService BuildService() { X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL) { User = "someone@mydomain.mygbiz.com", Scopes = new[] { DriveService.Scope.DriveFile } }.FromCertificate(certificate)); var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Drive API Sample", }); return service; } </code></pre> <p>When I try to build this code it seems all fine, but when I run it I get the following error. </p> <p>A first chance exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll</p> <p>Additional information: Det går inte att hitta det begärda objektet. (Translated : The requested object cannot be found)</p> <p>If there is a handler for this exception, the program may be safely continued.</p> <p>The error occurs on this line:</p> <pre><code>X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable); </code></pre> <p>Anyone have any ideas?</p> <p>Update 2013 Oct 31 I have tried this code:</p> <pre><code>{ Console.WriteLine("Drive API - Service Account"); Console.WriteLine("=========================="); String serviceAccountEmail = "&lt;some email&gt;@developer.gserviceaccount.com"; var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { User = "&lt;someuser&gt;@&lt;mydomain&gt;.mygbiz.com", Scopes = new[] { DriveService.Scope.Drive } }.FromCertificate(certificate)); // Create the service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "DrvMgr", }); Console.WriteLine("Executing listing"); FileList UserFiles = service.Files.List().Execute(); </code></pre> <p>I get this error message:</p> <p>An unhandled exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.dll</p> <p>Additional information: Error:"access_denied", Description:"", Uri:""</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload