2012年3月13日
by Shoji Nakata
Google Appsを利用するアプリケーションを作成する場合、Google Appsが有償版か無償版かでロジックを振り分けたい場合があります。
そのような場合、Google Admin Settings APIを使ってエディションを取得するのですが、このAPIは従来有償版のみに提供されていたAPIでした。
しかし、昨年末Google Appsの開発者ブログでAdmin Settings APIを含むいくつかのAPIが全エディションで利用できるようになったとのアナウンスがありました。
詳細は以下。
管理 API がすべての Google Apps エディションで
と言うことで、早速試してみます。まずはサンプルコードです。
public void getEdition() throws Exception{
String adminEmail = "admin@example.com";
String password = "administrator";
String domain = "example.com";
String appName = "GetEditionSample";
DomainSettingsService service
= new DomainSettingsService(adminEmail, password, domain, appName);
System.out.println("Edition[" + domain + "]: " + service.getDomainEdition());
}
ドメイン「example.com」でGoogle Appsの有償版を利用している場合、上記のコードを実行すると以下の様な結果が返されます。
Edition[example.com]: premier
ここまではOKですね。では次にドメイン「example.com」でGoogle Appsの無償版を使っている場合はどうなるのか試してみます。過去においては無償版に対してこのコードを実行した場合は403エラーが返されていたのですが、現在では以下の様な結果が得られるハズです。
Edition[example.com]: standard
では、実行。
Exception in thread "main" com.google.gdata.util.ServiceForbiddenException: Domain cannot use API <HTML> <HEAD> <TITLE>Domain cannot use API</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>Domain cannot use API</H1> <H2>Error 403</H2> </BODY> </HTML> at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:597) at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) at com.google.gdata.client.Service.getEntry(Service.java:1352) at com.google.gdata.client.GoogleService.getEntry(GoogleService.java:567) at com.google.gdata.client.Service.getEntry(Service.java:1278) at com.google.gdata.client.appsforyourdomain.AppsForYourDomainService.getEntry(AppsForYourDomainService.java:118) at com.google.gdata.client.appsforyourdomain.adminsettings.DomainSettingsService.getDomainEdition(DomainSettingsService.java:212) at mywork.AdminSettingsApiSample.getEdition(AdminSettingsApiSample.java:94) at mywork.AdminSettingsApiSample.main(AdminSettingsApiSample.java:70)
・・・
・・・・・・
・・・・・・・・・
あれ?
期待した結果が得られない・・・うーーん・・・何でか分からず悩んでいたのですが、ひょんなことから原因が分かりました。
Admin Settings APIを利用するためにはGoogle Apps管理画面から「provisionning APIを有効にする」のチェックを入れておく必要があります。
そんなのどこにも書いてないじゃん・・・orz
ま、とにかく上記のチェックを入れるとちゃんと無償版でも正しい結果が得られました。