New Google Drive Directory APIs error out: Bad request
Asked Answered
S

1

2

I am using below piece of code to list all domain users in my simple Console application

        var certificate = new X509Certificate2("D:\\3acf2c2008cecd33b43de27e30016a72e1482c41-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable);

        var privateKey = certificate.Export(X509ContentType.Cert);
        var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
        {
            ServiceAccountId = "877926787679-b7fd15en1sh2oc65e164v90cfcvrfftq@developer.gserviceaccount.com",
            Scope = DirectoryService.Scopes.AdminDirectoryUserReadonly.GetStringValue(),
            ServiceAccountUser = "[email protected]"
        };

        var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);

        DirectoryService dirService = new DirectoryService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
            ApplicationName = "My APP"
        });
        Users users = dirService.Users.List().Execute();

Execute() method errors out saying Bad Request.

Questions:

  1. How to overcome this issue?
  2. Does this Admin SDK support trial version of Google APP account?
  3. I have updated service account Client ID in Google Console and also updated in Admin Console with below scopes https://www.googleapis.com/auth/admin.directory.group https://www.googleapis.com/auth/admin.directory.user and also set API access check box. Do I missing something in settings?
Sequential answered 19/7, 2013 at 15:44 Comment(0)
D
2

Like JoBe said, you should include the domain parameter.

happy_user = service.users().list(domain='mydomain.com').execute()

This has worked for me.

Disaccord answered 24/7, 2013 at 1:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.