2014-06-24 4 views
2

Google Dotnet API Admin SDK를 제대로 사용해 보려고합니다.Google Dotnet API - Admin SDK 그룹 - 잘못된 요청 오류 받기

모든 그룹의 목록을 검색하려고 할 때 약간의 오류가 발생합니다. 나는 아직도 문서 (어떤 메소드 나 함수를 사용할 지 등)에 혼란 스럽다. 내가 지금이

코드 : 말

using System; 
using System.IO; 
using System.Threading; 

using Google.Apis.Auth.OAuth2; 
using Google.Apis.Services; 
using Google.Apis.Util.Store; 

using Google.Apis.Admin.Directory.directory_v1; 
using Google.Apis.Admin.Directory.directory_v1.Data; 

namespace GoogleConsoleApp 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      UserCredential credential; 

      using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)) 
      { 
       credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets, 
        new[] { DirectoryService.Scope.AdminDirectoryGroup, DirectoryService.Scope.AdminDirectoryGroupReadonly }, 
        "user", CancellationToken.None, new FileDataStore("Tasks.Auth.Store")).Result; 
      } 

      var dirSvc = new DirectoryService(new BaseClientService.Initializer() 
      { 
       HttpClientInitializer = credential, 
       ApplicationName = "Groups API Sample", 
      }); 

      Groups myGroups = dirSvc.Groups.List().Execute(); 

꽤 많이 오류 아웃 :

Unhandled Exception: Google.GoogleApiException: Google.Apis.Requests.RequestError 
Bad Request [400] 
Errors: [Message [Bad Request] Location [ - ] Reason[badRequest] Domain[global]] 

은 이미 개발자 콘솔에서 필요한 API를 사용하도록 설정했습니다.

이 문제에 대한 도움을 주시면 감사하겠습니다.

업데이트 : 나는 또한 (documentation에 따라)이 방법을 시도 :

Google.Apis.Admin.Directory.directory_v1.GroupsResource.ListRequest lreq = new GroupsResource.ListRequest(dirSvc); 
      Groups grp2 = lreq.Execute(); 

하지만 여전히 같은 오류가 발생합니다.

+0

1.Can는 요청과의 피들러 출력을 추가 응답? 2. 또한 Google API 탐색기 (https://developers.google.com/apis-explorer/#p/admin/directory_v1/directory.groups.list)에서 작동하는지 확인할 수 있습니다 – peleyal

+0

사실 이후의 사이드 노트 방법 - 요청을 수행하는 서버/컴퓨터의 시간이 서버의 Google 시간과 동일한 지 확인해야합니다. – DFTR

답변

3

요청의 도메인을 명시 적으로 설정해야합니다. 실수는 다른 유형의 요청처럼 도메인을 비워두면 전체 도메인을 검색한다고 가정하는 것입니다. 이 경우 대신 고객의 그룹을 검색하려고합니다.이 그룹은 비어 있습니다. api spec에있는 메모에서. 작동

When retrieving:

  • All groups for a sub-domain — Use the domain argument with the domain's name.
  • All groups for the account — Use the customer argument with either my_customer or the account's customerId value. As an account administrator, use the string my_customer to represent your account's customerId. If you are a reseller accessing a resold customer's account, use the resold account's customerId. For the customerId value use the account's primary domain name in the Retrieve all users in a domain operation's request. The resulting response has the customerId value.
  • Using both domain and customer arguments — The API returns all the groups for the domain.
  • Not using the domain and customer arguments — The API returns all the groups for the account associated with my_customer. This is the account customerId of the administrator making the API request.

예 : 작동하지 않고 정확한 동일한 오류가 발생합니다

GroupsResource.ListRequest groupRequest = _service.Groups.List(); 
groupRequest.Domain = "YourDomain"; 
Groups domainGroups = groupRequest.Execute(); 

예 :

GroupsResource.ListRequest groupRequest = _service.Groups.List(); 
Groups domainGroups = groupRequest.Execute(); 
관련 문제