Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using Below piece of code to get files with service account.

        var certificate = new X509Certificate2("D:\\05-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable);
        var privateKey = certificate.Export(X509ContentType.Cert);
        var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
        {
            ServiceAccountId = "877564787679-glrhdp0gclc9mbj77qe4998dkc6mfj62@developer.gserviceaccount.com",
            Scope = DriveService.Scopes.Drive.GetStringValue(),
            ServiceAccountUser = "[email protected]"
        };
        var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
        DriveService service = new DriveService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
            ApplicationName = "My APP",
        });

        FilesResource.ListRequest request = service.Files.List();
        FileList files = request.Execute();

Here Execute() api is giving exception

Error occurred while sending a direct message or getting the response.

Edit: Project is based on the settings mentioned @ https://code.google.com/p/google-api-dotnet-client/wiki/Build

Edit 2: I have proper settings in CPanel based on service account

share|improve this question
    
Did you go through the delegation that's explained on developers.google.com/drive/delegation? –  Burcu Dogan Jul 17 '13 at 13:05
    
Thanks Burcu, It starts working.... I have created a new Google APP account and did the setting mentioned @ developers.google.com/drive/delegation....But I think It takes some time to take effect....:-) –  Jeevan Jul 17 '13 at 13:15
    
Good to know it's working now. –  Burcu Dogan Jul 17 '13 at 20:57
    
Hi @Jeevan I am also trying to do the same.But every time they want authentication.Can you please help me in that.My mail id [email protected]. Can you please share your code with me. –  amit ghosh Jul 20 '13 at 9:21
add comment

1 Answer

I was having the same problem. I got it working eventually; I had a few things wrong.

  1. I went to the Google Cloud Console and regenerated and downloaded my key file. Go to APIs & auth->Registered Apps.
  2. The ONLY properties I put in the provider object are .ServiceAccountId and .Scope.
  3. I had to replace Scope with the actual scope and not use the enum value (This is only a problem because I am using VB). I'm working in Fusion Tables and the scope was rendering as just "Fusiontables" because VB.NET does not use the GetStringValue() enum function. Now I'm using "https://www.googleapis.com/auth/fusiontables". Go here for a list of valid scopes.
  4. For the ServiceAccountId, I used the service account "Email address:" with the "@" in it. ([email protected]), and not the one they label as a "Client ID:" in the console (12345.apps.googleusercontent.com).

Hopefully this helps others.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.