新的Google Drive Directory API出错:请求错误

时间:2013-07-19 15:44:56

标签: google-admin-sdk

我使用下面的代码在我的简单控制台应用程序中列出所有域用户

        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 = "user1@05.mygbiz.com"
        };

        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();

执行()方法错误,说错误请求。

问题:

  1. 如何克服这个问题?
  2. 此Admin SDK是否支持Google APP帐户的试用版?
  3. 我在Google控制台中更新了服务帐户客户端ID,并在管理控制台中使用以下范围进行了更新 https://www.googleapis.com/auth/admin.directory.group https://www.googleapis.com/auth/admin.directory.user 并设置API访问复选框。我在设置中遗漏了什么吗?

1 个答案:

答案 0 :(得分:2)

像JoBe所说,你应该包含domain参数。

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

这对我有用。