2011-11-22 2 views
0

내 Google Apps for Business 도메인에서 사용할 수있는 그룹 (및 해당 회원)을 열거하고 싶지만 관련 API를 찾는 데 문제가 있습니다. documentation page에서 사용할 수있는 모든 항목은 이미 그룹 이름을 알고 있다고 가정하는 것 같습니다. 심지어 회원을 나열 할 방법이 없습니다.내 도메인에서 Google 그룹스를 열거하고 회원을 나열하려면 어떻게해야합니까?

API를, GDATA의 이전 버전은, 내가하고자하는 모든 것을위한 clear interface있다 - 그러나 그것은 및 개발 팀 suggesting that the new interface is preferable이다 (실제로는 명시 적으로 no such package will be provided가한다고) 메이븐 패키지를 제공하지 않습니다.

Google API를 사용하여 그룹을 GDATA API에서와 같은 방식으로 열거 할 수 있습니까?

답변

0

나는 마침내이 작업을 수행하는 방법을 발견했습니다. 인증을 포함한 기본 코드 :

public class GroupLister { 
    static HttpTransport transport = new NetHttpTransport(); 
    static HttpParser parser = new AtomParser(new XmlNamespaceDictionary()); 

    public GroupFeed listGroups(String domainName, String apiKey, 
      String username, String password) throws IOException { 
     HttpRequestFactory factory = createRequestFactory(transport, username, 
       password); 
     GoogleUrl url = new GoogleUrl(
       "https://apps-apis.google.com/a/feeds/group/2.0/" + domainName); 
     url.key = apiKey; 
     return factory.buildGetRequest(url).execute().parseAs(GroupFeed.class); 
    } 

    public HttpRequestFactory createRequestFactory(
      final HttpTransport transport, final String username, 
      final String password) { 
     return transport.createRequestFactory(new HttpRequestInitializer() { 
      public void initialize(HttpRequest request) throws IOException { 
       request.addParser(parser); 
       ClientLogin authenticator = new ClientLogin(); 
       authenticator.transport = transport; 
       authenticator.authTokenType = "apps"; 
       authenticator.username = username; 
       authenticator.password = password; 
       request.getHeaders().setAuthorization(
         authenticator.authenticate() 
           .getAuthorizationHeaderValue()); 
      } 
     }); 
    } 

} 

데이터 클래스 :

public class GroupFeed { 
    @Key 
    public Date updated; 
    @Key("entry") 
    public List<GroupEntry> groups; 
} 

public class GroupEntry { 
    @Key 
    public String id; 
    @Key("apps:property") 
    public List<PropertyEntry> properties; 
} 

public class PropertyEntry { 
    @Key("@name") 
    public String name; 
    @Key("@value") 
    public String value; 
} 

이 시행 & 오류 시도를 많이했다.