重要: このドキュメントは 2012 年より前に作成されたものです。このドキュメントで説明する認証オプション(OAuth 1.0、AuthSub、ClientLogin)は、2012 年 4 月 20 日をもって正式に非推奨となり、現在では利用できません。できるだけ早く OAuth 2.0 に移行することをおすすめします。
Google Sites Data API を使用すると、クライアント アプリケーションで Google サイト内のコンテンツにアクセスしたり、コンテンツを公開したり、コンテンツを変更したりできます。クライアント アプリケーションは、最近のアクティビティのリストをリクエストしたり、リビジョン履歴を取得したり、添付ファイルをダウンロードしたりすることもできます。
このガイドでは、Sites Data API の機能の概要を説明するだけでなく、Java クライアント ライブラリを使用して API を操作する例も紹介します。クライアント ライブラリの設定については、Google Data Java クライアント ライブラリ スタートガイドをご覧ください。Java クライアント ライブラリがクラシック サイト API とのやり取りに使用する基盤となるプロトコルの詳細については、プロトコル ガイドをご覧ください。
オーディエンス
このドキュメントは、Google Data Java クライアント ライブラリを使用して Google サイトとやり取りするクライアント アプリケーションを作成するデベロッパーを対象としています。
スタートガイド
Google サイトでは、認証に Google アカウントまたは G Suite アカウントが使用されます。すでにアカウントをお持ちの場合は、準備が整っています。お持ちでない場合は、新しいアカウントを作成できます。
ライブラリのインストール
クライアント ライブラリの設定とインストールについては、Google Data Java クライアント ライブラリ スタートガイドをご覧ください。Eclipse を使用している場合は、Google Data APIs Eclipse プラグインを使用してプロジェクトを設定する方法についても説明しています。始める前に次のものを用意してください。
- Java 1.5 以降をインストールする
- クライアント ライブラリをダウンロードする(
gdata-src.java.zipの最新バージョン) - 依存関係のリストをダウンロードする
- サンプル アプリケーション(
gdata-samples.java.zipの最新バージョン)をダウンロードします。
.jars をインストールしたら、プロジェクトに以下を含める必要があります。
java/lib/gdata-sites-2.0.jar- ここでのバージョン 2.0 は、以前の Google サイト API のバージョン 1.4 を対象としています。java/lib/gdata-core-1.0.jarjava/lib/gdata-client-1.0.jarjava/lib/gdata-spreadsheet-3.0.jar(リストページ / リストアイテムを操作する場合)
また、依存関係の JAR(gdata-media-1.0.jar、mail.jar、google-collect....jar)も必ず含めてください。
サンプル アプリケーションの実行
完全に動作するサンプル アプリケーションは、gdata-samples.java.zip ダウンロードの /java/sample/sites サブディレクトリにあります。ソースは、[ソース] タブからアクセスできる SVN リポジトリの /trunk/java/sample/sites/ でも入手できます。SitesDemo.java を使用すると、旧 Google サイト API の使用方法を示すさまざまな操作を実行できます。
なお、サンプルを実行するには java/sample/util/lib/sample-util.jar を含める必要があります。
独自のプロジェクトを開始する
ヒント: Eclipse プラグインを使用した簡単な設定については、Google Data API で Eclipse を使用するをご覧ください。
アプリケーションのニーズに応じて、複数のインポートが必要になります。次のインポートから始めることをおすすめします。
import com.google.gdata.client.*; import com.google.gdata.client.sites.*; import com.google.gdata.data.*; import com.google.gdata.data.acl.*; import com.google.gdata.data.media.*; import com.google.gdata.data.sites.*; import com.google.gdata.data.spreadsheet.*; // If working with listpages / listitems import com.google.gdata.util.*;
次に、クラシック サイト API へのクライアント接続を表す SitesService オブジェクトを設定する必要があります。
SitesService client = new SitesService("yourCo-yourAppName-v1");
applicationName 引数は、company-applicationname-version の形式で指定する必要があります。このパラメータはロギングに使用されます。
注: このガイドの残りの部分では、変数 client に SitesService を作成したことを前提としています。
以前の Sites API に対する認証
Java クライアント ライブラリは、一般公開フィードと非公開フィードのどちらでも使用できます。Sites Data API は、サイトの権限と実行しようとしているオペレーションに応じて、非公開フィードと公開フィードへのアクセスを提供します。たとえば、公開サイトのコンテンツ フィードを読み取ることはできても、更新することはできません。更新するには、認証されたクライアントが必要です。これは、ClientLogin ユーザー名/パスワード認証、AuthSub、または OAuth を介して行うことができます。
AuthSub、OAuth、ClientLogin の詳細については、Google Data APIs 認証の概要をご覧ください。
ヒント: この API は SSL(HTTPS)をサポートしています。AuthSub/OAuth を使用している場合は、SSL 経由でフィードをリクエストするために、https://sites.google.com/feeds/ のスコープを指定してください。また、G Suite ドメインの場合、管理コントロール パネルの [SSL を必須にする] 設定は API で尊重されます。client.useSsl(); を呼び出すことで、すべての API リクエストを HTTPS 経由で強制的に実行できます。
ウェブ アプリケーションの AuthSub
ウェブ アプリケーションの AuthSub 認証は、ユーザーを Google アカウントに対して認証する必要があるクライアント アプリケーションで使用する必要があります。オペレーターは、Google サイト ユーザーのユーザー名とパスワードにアクセスする必要はありません。AuthSub トークンのみが必要です。
AuthSub をウェブ アプリケーションに組み込む手順を表示する
1 回限りのトークンをリクエストする
ユーザーが初めてアプリケーションにアクセスする際には、認証を行う必要があります。通常、デベロッパーは、ユーザーを AuthSub 承認ページに誘導してユーザーを認証し、ドキュメントへのアクセスをリクエストするテキストとリンクを印刷します。Google Data Java クライアント ライブラリには、この URL を生成する関数が用意されています。以下のコードは、AuthSubRequest ページへのリンクを設定します。
import com.google.gdata.client.*; String nextUrl = "http://www.example.com/welcome.jsp"; String scope = "https://sites.google.com/feeds/"; boolean secure = true; boolean session = true; String authSubUrl = AuthSubUtil.getRequestUrl(nextUrl, scope, secure, session);
G Suite ホスト型ドメインのユーザーを認証する場合は:
import com.google.gdata.client.*; String hostedDomain = "example.com"; String nextUrl = "http://www.example.com/welcome.jsp"; String scope = "https://sites.google.com/feeds/"; // SSL is also supported boolean secure = true; boolean session = true; String authSubUrl = AuthSubUtil.getRequestUrl(hostedDomain, nextUrl, scope, secure, session);
getRequestUrl() メソッドは、いくつかのパラメータ(AuthSubRequest ハンドラで使用されるクエリ パラメータに対応)を受け取ります。
- next URL - ユーザーがアカウントにログインしてアクセスを許可した後に Google がリダイレクトする URL。上記の例では
http://www.example.com/welcome.jsp - スコープ - 上記の例では
https://sites.google.com/feeds/ - トークンが登録モードで使用されるかどうかを示すブール値。上記の例では
false - トークンが後でセッション トークンと交換されるかどうかを示す 2 つ目のブール値。上記の例では
true
セッション トークンにアップグレードする
Google Data API クライアント ライブラリで AuthSub を使用するをご覧ください。
セッション トークンに関する情報を取得する
Google Data API クライアント ライブラリで AuthSub を使用するをご覧ください。
セッション トークンの取り消し
ウェブ アプリケーションまたはインストール型/モバイル アプリケーションの OAuth
OAuth は AuthSub の代替として使用でき、ウェブ アプリケーションを対象としています。OAuth は、すべてのデータ リクエストにデジタル署名が必要で、ドメインを登録する必要があるという点で、AuthSub の安全な登録モードの使用に似ています。
インストール済みアプリケーションに OAuth を組み込む手順を表示する
リクエスト トークンを取得する
Google Data API クライアント ライブラリでの OAuth の使用をご覧ください。
リクエスト トークンを承認する
Google Data API クライアント ライブラリでの OAuth の使用をご覧ください。
アクセス トークンにアップグレードする
インストール済み/モバイル アプリケーションの ClientLogin
ClientLogin は、ユーザーを Google アカウントに対して認証する必要があるインストール済みアプリケーションまたはモバイル アプリケーションで使用する必要があります。初回実行時に、アプリケーションはユーザーにユーザー名とパスワードの入力を求めます。以降のリクエストでは、認証トークンが参照されます。
インストール済みアプリケーションに ClientLogin を組み込む手順を表示する
ClientLogin を使用するには、GoogleService から継承された SitesService オブジェクトの setUserCredentials() メソッドを呼び出します。クライアントがリクエストを行うユーザーのメールアドレスとパスワードを指定します。次に例を示します。
SitesService client = new SitesService("yourCo-yourAppName-v1"); client.setUserCredentials("example@gmail.com", "pa$$word");
ヒント: アプリケーションでユーザーの認証が初めて成功したら、認証トークンをデータベースに保存して、後で再利用できるようにします。アプリケーションを実行するたびにユーザーにパスワードの入力を求める必要はありません。詳細については、認証トークンを呼び出すをご覧ください。
Java アプリケーションで ClientLogin を使用する方法について詳しくは、Google Data API クライアント ライブラリで ClientLogin を使用するをご覧ください。
サイトフィード
サイトフィードを使用すると、ユーザーが所有しているか、閲覧権限を持っている Google サイトを一覧表示できます。既存のサイトの名前を変更するために使用することもできます。G Suite ドメインの場合は、サイト全体の作成やコピーにも使用できます。
リスティング サイト
サイトフィードをクエリするには、サイトフィード URL に HTTP GET を送信します。
https://sites.google.com/feeds/site/site/Java クライアントでは、SiteFeed クラスと SiteEntry クラスを使用してサイトフィードを操作できます。
public String getSiteFeedUrl() { String domain = "site"; // OR if the Site is hosted on G Suite, your domain (e.g. example.com) return "https://sites.google.com/feeds/site/" + domain + "/"; } public void getSiteFeed() throws IOException, ServiceException { SiteFeed siteFeed = client.getFeed(new URL(getSiteFeedUrl()), SiteFeed.class); for (SiteEntry entry : siteFeed.getEntries()){ System.out.println("title: " + entry.getTitle().getPlainText()); System.out.println("site name: " + entry.getSiteName().getValue()); System.out.println("theme: " + entry.getTheme().getValue()); System.out.println(""); } }
上記のスニペットは、サイトのタイトル、サイト名、サイトのテーマを出力します。フィード内の追加プロパティにアクセスするための他のゲッターも利用できます。
新しいサイトの作成
注: この機能は G Suite ドメインでのみご利用いただけます。
新しいサイトをプロビジョニングするには、新しい SiteEntry を作成し、サイトフィードでクライアントの insert() メソッドを呼び出します。
この例では、テーマ「slate」(省略可能な設定)で新しいサイトを作成し、サイト名(必須)と説明(省略可)を指定します。
public String getSiteFeedUrl() { String domain = "example.com"; return "https://sites.google.com/feeds/site/" + domain + "/"; } public SiteEntry createSite(String title, String summary, String theme, String tag) throws MalformedURLException, IOException, ServiceException { SiteEntry entry = new SiteEntry(); entry.setTitle(new PlainTextConstruct(title)); entry.setSummary(new PlainTextConstruct(summary)); Theme tt = new Theme(); tt.setValue(theme); entry.setTheme(tt); entry.getCategories().add(new Category(TagCategory.Scheme.TAG, tag, null)); return client.insert(new URL(getSiteFeedUrl()), entry); } SiteEntry newSiteEntry = createSite("My Site Title", "summary for site", "slate", "tag");
上記のリクエストにより、G Suite ドメイン example.com の下に新しいサイトが作成されます。したがって、サイトの URL は https://sites.google.com/a/example.com/my-site-title となります。
サイトが正常に作成されると、サーバーは SiteEntry オブジェクトを返します。このオブジェクトには、サーバーによって追加された要素(サイトへのリンク、サイトの ACL フィードへのリンク、サイト名、タイトル、概要など)が設定されています。
サイトをコピーする
注: この機能は G Suite ドメインでのみご利用いただけます。
サイトのコピーは、新しいサイトの作成と似ています。違いは、複製するサイトのセルフリンクを含むリンクを新しい SiteEntry に設定する必要があることです。以下に、新しいサイトの作成セクションで作成したサイトを複製する例を示します。
public SiteEntry copySite(String title, String summary, String sourceHref) throws MalformedURLException, IOException, ServiceException { SiteEntry entry = new SiteEntry(); entry.setTitle(new PlainTextConstruct(title)); entry.setSummary(new PlainTextConstruct(summary)); entry.addLink(SitesLink.Rel.SOURCE, Link.Type.ATOM, sourceHref); return client.insert(new URL(getSiteFeedUrl()), entry); } String sourceHref = newSiteEntry.getLink(SitesLink.Rel.SOURCE, Link.Type.ATOM).getHref(); SiteEntry myTwin = copySite("Duplicate Site", "A copy", sourceHref);
注意事項:
- コピーできるのは、認証されたユーザーが所有するサイトとサイト テンプレートのみです。
- サイト テンプレートをコピーすることもできます。Google サイトの設定ページで [このサイトをテンプレートとして公開] 設定がオンになっている場合、そのサイトはテンプレートです。
- 別のドメインからサイトをコピーするには、コピー元のサイトのオーナーとして登録されている必要があります。
サイトのメタデータを更新する
サイトの名前を変更したり、テーマ、カテゴリタグ、概要を変更したりするには、まず問題のサイトを含む SiteEntry を取得し、1 つ以上のプロパティを変更してから、SiteEntry の update() メソッドを呼び出す必要があります。この例では、前のサイトのテーマを変更し、サイトの名前を変更します。
myTwin.setTitle(new PlainTextConstruct("better-title")); Theme theme = myTwin.getTheme(); theme.setValue('iceberg'); myTwin.setTheme(theme); myTwin.getCategories().add(new Category(TagCategory.Scheme.TAG, "newTag", null)); SiteEntry updatedSiteEntry = myTwin.update(); System.out.println(updatedSiteEntry.getTitle().getPlainText();
ウェブアドレスのマッピング
ウェブアドレスのマッピングを使用すると、Google サイトのユーザーは自分のドメインを Google サイトにマッピングできます。たとえば、http://sites.google.com/a/domain.com/mysite の代わりに http://www.mydomainsite.com を使用できます。サイトのホスティング場所によっては、サイトのウェブアドレスのマッピングを手動で変更できます。詳しくは、ヘルプセンターの記事をご覧ください。
サイトのウェブアドレスのマッピングを取得する
サイトのウェブアドレス マッピングを返すには、with-mappings=true パラメータを使用してサイトのエントリ/フィードを取得します。
SiteQuery query = new SiteQuery(new URL("https://sites.google.com/feeds/site/siteName")); query.setWithMappings(true); SiteFeed feed = service.getFeed(query, SiteFeed.class); for (SiteEntry entry : feed.getEntries()) { System.out.println("Mappings for '" + entry.getSiteName().getValue() + "':"); for (Link link : entry.getWebAddressMappingLinks()) { System.out.println(" " + link.getHref()); } }
既存のマッピングは、rel='webAddressMapping' の link として表示されます。たとえば、上記の例では、サイト http://sites.google.com/site/myOtherTestSite を指す webAddressMapping が 3 つあります。
ウェブアドレスのマッピングを変更する
注: ウェブアドレス マッピングを使用する場合は、すべての GET/POST/PUT オペレーションで with-mappings=true パラメータを指定する必要があります。パラメータがない場合、サイト エントリ(GET)で webAddressMapping は返されず、エントリからマッピングを更新/削除(PUT)する際に考慮されません。
マッピングを追加、更新、削除するには、新しいサイトを作成するか、サイトのメタデータを更新する際に、そのようなリンクを指定、変更、削除します。with-mappings=true パラメータはサイトフィード URI に含める必要があります。注: アドレス マッピングを更新するには、サイト管理者である必要があります。G Suite でホストされているサイトの場合は、ドメイン管理者である必要があります。
たとえば、次のリクエストは http://www.mysitemapping.com マッピングを http://www.my-new-sitemapping.com に更新し、エントリからリンクを除外することで http://www.mysitemapping2.com を削除します。
SiteEntry entry = client.getEntry(new URL("https://sites.google.com/feeds/site/site/siteName?with-mappings=true"), SiteEntry.class); // Modify mappings (remove all mappings, add some of them again, add modified mappings) entry.removeLinks(SitesLink.Rel.WEBADDRESSMAPPING, Link.Type.HTML); entry.addLink(SitesLink.Rel.WEBADDRESSMAPPING, Link.Type.HTML, "http://www.my-new-sitemapping.com"); // Update the entry with the mappings. entry.update();
なお、ウェブアドレスのマッピングは、サイトの作成時やコピー時にも指定できます。
アクティビティ フィード
アクティビティ フィードを取得することで、サイトの最近のアクティビティ(変更)を取得できます。アクティビティ フィードの各エントリには、サイトに加えられた変更に関する情報が含まれています。
アクティビティ フィードをクエリするには、アクティビティ フィードの URL に HTTP GET を送信します。
https://sites.google.com/feeds/activity/site/siteName
Java クライアントで、ActivityFeed クラスを使用して ActivityEntry オブジェクトを返します。
public String buildActivityFeedUrl() { String domain = "site"; // OR if the Site is hosted on G Suite, your domain (e.g. example.com) String siteName = "mySite"; return "https://sites.google.com/feeds/activity/" + domain + "/" + siteName + "/"; } public void getActivityFeed() throws IOException, ServiceException { ActivityFeed activityFeed = client.getFeed(new URL(buildActivityFeedUrl()), ActivityFeed.class); for (BaseActivityEntry<?> entry : activityFeed.getEntries()){ System.out.println(entry.getSummary().getPlainText()); System.out.println(" revisions link: " + entry.getRevisionLink().getHref()); } }
注: このフィードにアクセスするには、サイトの共同編集者または所有者である必要があります。クライアントは、AuthSub、OAuth、または ClientLogin トークンを使用して認証する必要があります。Google サイトサービスに対する認証をご覧ください。
リビジョン フィード
コンテンツ エントリの変更履歴を取得するには、エントリの変更リンクに HTTP GET を送信します。
https://sites.google.com/feeds/revision/site/siteName/CONTENT_ENTRY_ID
この例では、コンテンツ フィードをクエリし、最初のコンテンツ エントリの改訂フィードを取得します。
ContentFeed contentFeed = client.getFeed(new URL(buildContentFeedUrl()), ContentFeed.class); URL revisionFeedUrl = new URL(contentFeed.getEntries().get(0).getRevisionLink().getHref()); // use first entry public void getRevisionFeed(String revisionFeedUrl) throws IOException, ServiceException { RevisionFeed revisionFeed = client.getFeed(revisionFeedUrl, RevisionFeed.class); for (BaseContentEntry<?> entry : revisionFeed.getEntries()){ System.out.println(entry.getTitle().getPlainText()); System.out.println(" updated: " + entry.getUpdated().toUiString() + " by " + entry.getAuthors().get(0).getEmail()); System.out.println(" revision #: " + entry.getRevision().getValue()); } }
注: このフィードにアクセスするには、サイトの共同編集者またはオーナーである必要があります。クライアントは、AuthSub、OAuth、または ClientLogin トークンを使用して認証する必要があります。Google サイトサービスに対する認証をご覧ください。
コンテンツ フィード
コンテンツ フィードを取得する
コンテンツ フィードには、サイトの最新のコンテンツが一覧表示されます。HTTP GET をコンテンツ フィードの URL に送信することでアクセスできます。
https://sites.google.com/feeds/content/site/siteName
| フィード パラメータ | 説明 |
|---|---|
site | 「site」または G Suite でホストされているドメインのドメイン(例: example.com)。 |
siteName | サイトのウェブスペース名。サイトの URL(例: mySite)で確認できます。 |
コンテンツ フィードを取得する例:
public String buildContentFeedUrl() { String domain = "site"; // OR if the Site is hosted on G Suite, your domain (e.g. example.com) String siteName = "mySite"; return "https://sites.google.com/feeds/content/" + domain + "/" + siteName + "/"; } ContentFeed contentFeed = client.getFeed(new URL(buildContentFeedUrl()), ContentFeed.class);
結果の contentFeed は、サーバーからのレスポンスを含む ContentFeed オブジェクトです。contentFeed の各エントリは、ユーザーのサイト内の異なるページまたはアイテムを表します。ContentFeed には、BaseContentEntry から継承されたさまざまなタイプのオブジェクト(ListItemEntry、ListPageEntry、AttachmentEntry、WebAttachmentEntry、FileCabinetPageEntry、AnnouncementsPageEntry、AnnouncementEntry、WebPageEntry、CommentEntry)が含まれます。
ContentFeed のさまざまなタイプのエントリを一覧表示する例を次に示します。エントリのタイプごとに異なるプロパティが含まれていますが、ここではすべてを説明しません。
public String getContentBlob(BaseContentEntry<?> entry) { return ((XhtmlTextConstruct) entry.getTextContent().getContent()).getXhtml().getBlob(); } // Extracts an entry's numeric ID. private String getEntryId(String selfLink) { return selfLink.substring(selfLink.lastIndexOf("/") + 1); } public void printContentEntries(ContentFeed contentFeed) { System.out.println("Listing all WebPageEntry:"); for (WebPageEntry entry : contentFeed.getEntries(WebPageEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); if (entry.getParentLink() != null) { System.out.println(" parent id: " + getEntryId(entry.getParentLink().getHref())); } System.out.println(" author: " + entry.getAuthors().get(0).getEmail()); System.out.println(" content: " + getContentBlob(entry)); } System.out.println("Listing all ListPageEntry:"); for (ListPageEntry entry : contentFeed.getEntries(ListPageEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); for (Column col : entry.getData().getColumns()) { System.out.print(" [" + col.getIndex() + "] " + col.getName() + "\t"); } } for (ListItemEntry entry : contentFeed.getEntries(ListItemEntry.class)) { for (Field field : entry.getFields()) { System.out.print(" [" + field.getIndex() + "] " + field.getValue() + "\t"); } System.out.println("\n"); } System.out.println("Listing all FileCabinetPageEntry:"); for (FileCabinetPageEntry entry : contentFeed.getEntries(FileCabinetPageEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); System.out.println(" content: " + getContentBlob(entry)); } System.out.println("Listing all CommentEntry:"); for (CommentEntry entry : contentFeed.getEntries(CommentEntry.class)) { System.out.println(" in-reply-to: " + entry.getInReplyTo().toString()); System.out.println(" content: " + getContentBlob(entry)); } System.out.println("Listing all AnnouncementsPageEntry:"); for (AnnouncementsPageEntry entry : contentFeed.getEntries(AnnouncementsPageEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); System.out.println(" content: " + getContentBlob(entry)); } System.out.println("Listing all AnnouncementEntry:"); for (AnnouncementEntry entry : contentFeed.getEntries(AnnouncementEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); if (entry.getParentLink() != null) { System.out.println(" parent id: " + getEntryId(entry.getParentLink().getHref())); } System.out.println(" draft?: " + entry.isDraft()); System.out.println(" content: " + getContentBlob(entry)); } System.out.println("Listing all AttachmentEntry:"); for (AttachmentEntry entry : contentFeed.getEntries(AttachmentEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); if (entry.getParentLink() != null) { System.out.println(" parent id: " + getEntryId(entry.getParentLink().getHref())); } if (entry.getSummary() != null) { System.out.println(" description: " + entry.getSummary().getPlainText()); } System.out.println(" revision: " + entry.getRevision().getValue()); MediaContent content = (MediaContent) entry.getContent(); System.out.println(" src: " + content.getUri()); System.out.println(" content type: " + content.getMimeType().getMediaType()); } System.out.println("Listing all WebAttachmentEntry:"); for (WebAttachmentEntry entry : contentFeed.getEntries(WebAttachmentEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); System.out.println(" id: " + getEntryId(entry)); if (entry.getParentLink() != null) { System.out.println(" parent id: " + getEntryId(entry.getParentLink().getHref())); } if (entry.getSummary() != null) { System.out.println(" description: " + entry.getSummary().getPlainText()); } System.out.println(" src: " + ((MediaContent) entry.getContent()).getUri()); } }
注: このフィードでは、サイトの共有権限に応じて認証が必要になる場合があります。サイトが非公開の場合、クライアントは AuthSub、OAuth、または ClientLogin トークンを使用して認証する必要があります。Google サイトサービスに対する認証をご覧ください。
コンテンツ フィードのクエリの例
コンテンツ フィードは、標準の Google Data API クエリ パラメータと、クラシック Sites API 固有のパラメータを使用して検索できます。詳細とサポートされているパラメータの一覧については、リファレンス ガイドをご覧ください。
注: このセクションの例では、コンテンツ フィードの取得の buildContentFeedUrl() メソッドを使用しています。
特定のエントリ種類の取得
特定のエントリタイプのみを取得するには、kind パラメータを使用します。この例では、attachment エントリのみが返されます。
ContentQuery query = new ContentQuery(new URL(buildContentFeedUrl())); query.setKind("webpage"); ContentFeed contentFeed = client.getFeed(query, ContentFeed.class); for (AttachmentEntry entry : contentFeed.getEntries(AttachmentEntry.class)) { System.out.println(entry.getTitle().getPlainText()); }
複数のエントリ タイプを返すには、各 kind を「,」で区切ります。次の例では、filecabinet エントリと listpage エントリを返します。
URL url = new URL(buildContentFeedUrl() + "?kind=filecabinet,listpage"); ContentFeed contentFeed = client.getFeed(url, ContentFeed.class); for (FileCabinetPageEntry entry : contentFeed.getEntries(FileCabinetPageEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); } for (ListPageEntry entry : contentFeed.getEntries(ListPageEntry.class)) { System.out.println(" title: " + entry.getTitle().getPlainText()); }
パスでページを取得する
Google サイト内のページの相対パスがわかっている場合は、path パラメータを使用してその特定のページを取得できます。この例では、http://sites.google.com/site/siteName/path/to/the/page にあるページが返されます。
ContentQuery query = new ContentQuery(new URL(buildContentFeedUrl())); query.setPath("/path/to/the/page"); ContentFeed contentFeed = client.getFeed(query, ContentFeed.class); for (BaseContentEntry<?> entry : contentFeed.getEntries()) { System.out.println(" title: " + entry.getTitle().getPlainText()); }
親ページの下にあるすべてのエントリを取得する
ページのコンテンツ エントリ ID(以下の例では「1234567890」)がわかっている場合は、parent パラメータを使用して、そのすべての子エントリ(存在する場合)を取得できます。
ContentQuery query = new ContentQuery(new URL(buildContentFeedUrl())); query.setParent("1234567890"); ContentFeed contentFeed = client.getFeed(query, ContentFeed.class);
その他のパラメータについては、リファレンス ガイドをご覧ください。
コンテンツの作成
注: サイトのコンテンツを作成する前に、クライアントでサイトを設定していることを確認してください。client.site = "siteName";
新しいコンテンツ(ウェブページ、リストページ、ファイルキャビネット ページ、お知らせページなど)は、コンテンツ フィードに HTTP POST を送信することで作成できます。
https://sites.google.com/feeds/content/site/siteName
サポートされているノードタイプの一覧については、リファレンス ガイドの kind パラメータをご覧ください。
新しいアイテム / ページの作成
この例では、サイトの最上位に新しい webpage を作成し、ページ本文の XHTML を含め、見出しのタイトルを「New WebPage Title」に設定します。
private void setContentBlob(BaseContentEntry<?> entry, String pageContent) { XmlBlob xml = new XmlBlob(); xml.setBlob(pageContent); entry.setContent(new XhtmlTextConstruct(xml)); } public WebPageEntry createWebPage(String title, String content) throws MalformedURLException, IOException, ServiceException { WebPageEntry entry = new WebPageEntry(); entry.setTitle(new PlainTextConstruct(title)); setContentBlob(entry, content); // Entry's HTML content return client.insert(new URL(buildContentFeedUrl()), entry); } WebPageEntry createdEntry = createWebPage("New Webpage Title", "<b>HTML content</b>"); System.out.println("Created! View at " + createdEntry.getHtmlLink().getHref());
リクエストが成功すると、createdEntry にはサーバーで作成されたエントリのコピーが含まれます。
カスタム URL パスでアイテムやページを作成する
デフォルトでは、上記の例は URL http://sites.google.com/site/siteName/new-webpage-title の下に作成され、ページの見出しは「New Webpage Title」になります。つまり、URL の <atom:title> は new-webpage-title に正規化されます。ページの URL パスをカスタマイズするには、<sites:pageName> 要素を設定します。
この例では、見出しが「ファイル ストレージ」の新しい filecabinet ページを作成しますが、<sites:pageName> 要素を指定することで、http://sites.google.com/site/siteName/files(http://sites.google.com/site/siteName/file-storage ではなく)という URL の下にページを作成します。
public FileCabinetPageEntry createFileCabinetPage(String title, String content, String customPageName) throws MalformedURLException, IOException, ServiceException { FileCabinetPageEntry entry = new FileCabinetPageEntry(); entry.setTitle(new PlainTextConstruct(title)); setContentBlob(entry, content); // Entry's HTML content entry.setPageName(new PageName(customPageName)); // Upload to a custom page path return client.insert(new URL(buildContentFeedUrl()), entry); } FileCabinetPageEntry createdEntry = createFileCabinetPage("File Storage", "<b>HTML content</b>", "files"); System.out.println("Created! View at " + createdEntry.getHtmlLink().getHref());
サーバーは、ページの URL パスの命名に次の優先順位ルールを使用します。
<sites:pageName>(存在する場合)。a-z, A-Z, 0-9, -, _を満たす必要があります。<atom:title>。pageName が存在しない場合は null にすることはできません。正規化とは、空白文字をトリミングして '-' に折りたたみ、a-z, A-Z, 0-9, -, _に一致しない文字を削除することです。
サブページの作成
親ページの下にサブページ(子)を作成するには、エントリで親リンクを設定する必要があります。リンクの href 属性を親ノードの自己リンクに設定します。
public AnnouncementEntry postAnnouncement(String title, String content, AnnouncementsPageEntry parentPage) throws MalformedURLException, IOException, ServiceException { AnnouncementEntry entry = new AnnouncementEntry(); entry.setTitle(new PlainTextConstruct(title)); setContentBlob(entry, content); // Entry's HTML content // Set the entry's parent link to create the announcement under that page. entry.addLink(SitesLink.Rel.PARENT, Link.Type.ATOM, parentPage.getSelfLink().getHref()); return client.insert(new URL(buildContentFeedUrl()), entry); } ContentFeed contentFeed = client.getFeed(new URL(buildContentFeedUrl() + "?kind=announcementspage"), ContentFeed.class); AnnouncementEntry createdEntry = postAnnouncement("Party!!", "My place, this weekend", contentFeed.getEntries().get(0)); System.out.println("New post by " + createdEntry.getAuthors().get(0).getName());
上記の例では、ユーザーのコンテンツ フィードで見つかった最初のお知らせページの新しい announcement を作成します。お知らせのタイトルは「Party!!」、内容は「My place, this weekend」に設定されています。
ページ テンプレート
ページ テンプレートの作成
ページ テンプレートの作成プロセスは、新しいアイテム/ページの作成とサブページの作成と同じです。異なるのは、それぞれ 'http://schemas.google.com/g/2005#template' と 'template' に設定された term と label を持つ category が追加されることです。
この例では、新しい webpage テンプレートを作成します。
// The template webpage entry. WebPageEntry entry = new WebPageEntry(); // Set title and content. entry.setTitle(new PlainTextConstruct("Page template title")); XmlBlob xml = new XmlBlob(); xml.setBlob("Content for page template"); entry.setContent(new XhtmlTextConstruct(xml)); // Set the template category Category TEMPLATE_CATEGORY = new Category(TemplateCategory.Scheme.LABELS, TemplateCategory.Term.TEMPLATE, TemplateCategory.Label.TEMPLATE); entry.getCategories().add(TEMPLATE_CATEGORY); // Insert the template webpage entry. WebPageEntry createdEntry = client.insert(new URL("https://sites.google.com/feeds/content/site/siteName"), entry);
テンプレートからページを作成する
ページ テンプレートの作成と同様に、ページ テンプレートのセルフリンクを指す rel='http://schemas.google.com/sites/2008#template' を含む <link> を含めることで、テンプレートから新しいページをインスタンス化できます。
この例では、新しい filecabinet テンプレートを作成し、そのテンプレートから新しい filecabinet ページをインスタンス化します。
URL feedUrl = new URL("https://sites.google.com/feeds/content/site/siteName"); // 1. Create file cabinet page template FileCabinetPageEntry inputTemplateEntry = new FileCabinetPageEntry(); inputTemplateEntry.setTitle(new PlainTextConstruct("File cabinet page template title")); XmlBlob xml = new XmlBlob(); xml.setBlob("Content for page template"); inputTemplateEntry.setContent(new XhtmlTextConstruct(xml)); // Set the template category Category TEMPLATE_CATEGORY = new Category(TemplateCategory.Scheme.LABELS, TemplateCategory.Term.TEMPLATE, TemplateCategory.Label.TEMPLATE); inputTemplateEntry.getCategories().add(TEMPLATE_CATEGORY); // 2. Create file cabinet page template instance FileCabinetPageEntry templateEntry = client.insert(feedUrl, inputTemplateEntry); // Specify link to the page template FileCabinetPageEntry templateInstanceEntry = new FileCabinetPageEntry(); templateInstanceEntry.setTitle(new PlainTextConstruct("File cabinet template instance")); templateInstanceEntry.addLink(new Link(SitesLink.Rel.TEMPLATE, Link.Type.ATOM, templateEntry.getSelfLink().getHref())); FileCabinetPageEntry createdFileCabinetFromTemplate = client.insert(feedUrl, templateInstanceEntry);
注: テンプレートで <category> が定義されていても、エントリに 1 つ含める必要があります。また、<content> 要素を含めると、サーバーによって拒否されます。
ファイルのアップロード
Google サイトと同様に、API はファイル キャビネット ページまたは親ページへの添付ファイルのアップロードをサポートしています。
添付ファイルを親にアップロードするには、HTTP POST リクエストをコンテンツ フィードの URL に送信します。
https://sites.google.com/feeds/content/site/siteName
すべての添付ファイル タイプは親ページにアップロードする必要があります。そのため、アップロードしようとしている AttachmentEntry オブジェクトまたは WebAttachmentEntry オブジェクトに親リンクを設定します。詳しくは、サブページを作成するをご覧ください。
添付ファイルをアップロード中
この例では、ユーザーのコンテンツ フィードで見つかった最初の FileCabinetPageEntry に PDF ファイルをアップロードします。添付ファイルは、「Getting Started」というタイトルと「HR packet」という説明(省略可)で作成されます。
MimetypesFileTypeMap mediaTypes = new MimetypesFileTypeMap(); mediaTypes.addMimeTypes("application/msword doc"); mediaTypes.addMimeTypes("application/vnd.ms-excel xls"); mediaTypes.addMimeTypes("application/pdf pdf"); mediaTypes.addMimeTypes("text/richtext rtx"); // ... See a more complete list of mime types in the SitesHelper.java public AttachmentEntry uploadAttachment(File file, BasePageEntry<?> parentPage, String title, String description) throws IOException, ServiceException { AttachmentEntry newAttachment = new AttachmentEntry(); newAttachment.setMediaSource(new MediaFileSource(file, mediaTypes.getContentType(file))); newAttachment.setTitle(new PlainTextConstruct(title)); newAttachment.setSummary(new PlainTextConstruct(description)); newAttachment.addLink(SitesLink.Rel.PARENT, Link.Type.ATOM, parentPage.getSelfLink().getHref()); return client.insert(new URL(buildContentFeedUrl()), newAttachment); } ContentFeed contentFeed = client.getFeed(new URL(buildContentFeedUrl() + "?kind=filecabinet"), ContentFeed.class); FileCabinetPageEntry parentPage = contentFeed.getEntries(FileCabinetPageEntry.class).get(0); AttachmentEntry attachment = uploadAttachment( new File("/path/to/your/file.pdf"), parentPage, "Getting Started", "HR packet"); System.out.println("Uploaded!");
アップロードが成功すると、attachment に作成された添付ファイル エントリのコピーが含まれます。
フォルダへの添付ファイルのアップロード
FileCabinetPageEntry の既存のフォルダに添付ファイルをアップロードするには、'term' 属性がフォルダ名に設定されたカテゴリを含めます。たとえば、uploadAttachment() に次の行を追加します。
newAttachment.getCategories().add(new Category("http://schemas.google.com/sites/2008#folder", "FolderName"));
ウェブ アタッチメント
ウェブ添付ファイルは、特殊な種類の添付ファイルです。基本的には、ウェブ上の他のファイルへのリンクであり、ファイルキャビネットのリスティングに追加できます。この機能は、Google サイトの UI の [URL でファイルを追加] アップロード方法に類似しています。
注: ウェブ添付ファイルはファイル キャビネットでのみ作成できます。他の種類のページにアップロードすることはできません。
この例では、ユーザーのコンテンツ フィードで最初に見つかった FileCabinetPageEntry の下に WebAttachmentEntry を作成します。タイトルと説明(省略可)はそれぞれ「GoogleLogo」と「nice colors」に設定されています。
public WebAttachmentEntry uploadWebAttachment(String contentUrl, FileCabinetPageEntry filecabinet, String title, String description) throws MalformedURLException, IOException, ServiceException { MediaContent content = new MediaContent(); content.setUri(contentUrl); WebAttachmentEntry webAttachment = new WebAttachmentEntry(); webAttachment.setTitle(new PlainTextConstruct(title)); webAttachment.setSummary(new PlainTextConstruct(description)); webAttachment.setContent(content); webAttachment.addLink(SitesLink.Rel.PARENT, Link.Type.ATOM, filecabinet.getSelfLink().getHref()); return client.insert(new URL(buildContentFeedUrl()), webAttachment); } ContentFeed contentFeed = client.getFeed(new URL(buildContentFeedUrl() + "?kind=filecabinet"), ContentFeed.class); FileCabinetPageEntry parentPage = contentFeed.getEntries(FileCabinetPageEntry.class).get(0); WebAttachmentEntry webAttachment = uploadWebAttachment("http://www.google.com/images/logo.gif", parentPage, "Google's Logo", "nice colors"); System.out.println("Web attachment created!");
POST は、ユーザーのファイル キャビネットに、'http://www.google.com/images/logo.gif' の画像を参照するリンクを作成します。
コンテンツの更新
ページのメタデータや HTML コンテンツを更新する
BaseContentEntry タイプのメタデータ(タイトル、pageName など)とページ コンテンツは、エントリの update() メソッドを使用して編集できます。これにより、エントリの edit リンクに HTTP PUT リクエストが送信されます。
次の変更で ListPageEntry を更新する例を次に示します。
- タイトルが「Updated Title」に変更されます。
- ページの HTML コンテンツが「<p>Updated HTML Content</p>」に更新されます。
- リストの最初の列の見出しが「所有者」に変更されます
ContentFeed contentFeed = client.getFeed( new URL(buildContentFeedUrl() + "?kind=listpage"), ContentFeed.class); ListPageEntry listPage = contentFeed.getEntries(ListPageEntry.class).get(0); // Update first list page found // Update title listPage.setTitle(new PlainTextConstruct("Updated Title")); // Update HTML content XmlBlob xml = new XmlBlob(); xml.setBlob("<p>Updated HTML Content</p>"); listPage.setContent(new XhtmlTextConstruct(xml)); // Change first column's heading listPage.getData().getColumns().get(0).setName("Owner"); // listPage.setPageName(new PageName("new-page-path")); // You can also change the page's URL path ListPageEntry updatedEntry = listPage.update(); System.out.println("ListPage updated!");
添付ファイルの内容を更新する
AttachmentEntry の場合、エントリの MediaSource を設定し、エントリの updateMedia(boolean) メソッドを使用してコンテンツを更新することもできます。
この例では、既存の添付ファイルの内容を更新します。
public AttachmentEntry updateFile(AttachmentEntry entry, File newFile) throws IOException, ServiceException { // See Uploading Attachments for the definition of mediaTypes. entry.setMediaSource(new MediaFileSource(newFile, mediaTypes.getContentType(newFile))); return entry.updateMedia(false); }
この例では、エントリの edit-media リンクに HTTP PUT リクエストを送信します。返される AttachmentEntry には、更新されたコンテンツが含まれます。
添付ファイルのメタデータとコンテンツの更新
updateMedia() メソッドを使用すると、同じ呼び出しで添付ファイルのメタデータとそのコンテンツを更新できます。ファイル コンテンツ、メタデータ、またはその両方のみを更新できるかどうか。
この例では、添付ファイルのタイトルを「New Title」に変更し、説明を更新して、ファイルの内容を新しい .zip ファイルに置き換えます。リクエストに新しいファイル コンテンツが含まれているため、AttachmentEntry の updateMedia() が使用されます。
public AttachmentEntry updateAttachment(AttachmentEntry entry, File newFile, String newTitle, String newDescription) throws IOException, ServiceException { // See Uploading Attachments for the definition of mediaTypes. entry.setMediaSource(new MediaFileSource(newFile, mediaTypes.getContentType(newFile))); entry.setTitle(new PlainTextConstruct(newTitle)); entry.setSummary(new PlainTextConstruct(newDescription)); return entry.updateMedia(true); } ContentFeed contentFeed = client.getFeed( new URL(buildContentFeedUrl() + "?kind=attachment&max-results=1"), ContentFeed.class); AttachmentEntry attachment = contentFeed.getEntries(AttachmentEntry.class).get(0); // Update first attachment found AttachmentEntry updatedAttachment = updateAttachment(attachment, new File("/path/to/file.zip"), "New Title", "better stuff");
コンテンツの削除
Google サイトからページまたはアイテムを削除するには、まずコンテンツ エントリを取得してから、エントリの delete() を呼び出します。
entry.delete();
サービス クラスの delete() メソッドを使用することもできます。このメソッドには、エントリの edit リンクと ETag 値を渡します。
client.delete(entry.getEditLink().getHref(), "*"); // Note: using "*" may overwrite another client's changes.
エントリが正常に削除されると、サーバーは HTTP 200 OK で応答します。
添付ファイルをダウンロードする
AttachmentEntry をダウンロードするには、エントリのコンテンツ src リンクに HTTP GET リクエストを送信します。
この例では、ユーザーのコンテンツ フィードで見つかった最初の AttachmentEntry をディレクトリ「/path/to/save/file/」にダウンロードします。
private void downloadFile(String downloadUrl, String fullFilePath) throws IOException, ServiceException { System.out.println("Downloading file from: " + downloadUrl); MediaContent mc = new MediaContent(); mc.setUri(downloadUrl); MediaSource ms = service.getMedia(mc); InputStream inStream = null; FileOutputStream outStream = null; try { inStream = ms.getInputStream(); outStream = new FileOutputStream(fullFilePath); int c; while ((c = inStream.read()) != -1) { outStream.write(c); } } finally { if (inStream != null) { inStream.close(); } if (outStream != null) { outStream.flush(); outStream.close(); } } } public void downloadAttachment(AttachmentEntry entry, String directory) throws IOException, ServiceException { String url = ((OutOfLineContent) entry.getContent()).getUri(); downloadFile(url, directory + entry.getTitle().getPlainText()); // Use entry's title for the save filename } ContentFeed contentFeed = client.getFeed( new URL(buildContentFeedUrl() + "?kind=attachment&max-results=1"), ContentFeed.class); downloadAttachment(contentFeed.getEntries(AttachmentEntry.class).get(0), "/path/to/save/file/"); System.out.println("Downloaded.");
ACL フィード
共有権限(ACL)の概要
ACL フィードの各 ACL エントリは、特定のエンティティ(ユーザー、ユーザーのグループ、ドメイン、またはデフォルトのアクセス(公開サイト))のアクセスロールを表します。エントリは、明示的なアクセス権を持つエンティティに対してのみ表示されます。Google サイトの UI の共有画面の [アクセス権を持つユーザー] パネルに表示されるメールアドレスごとに 1 つのエントリが表示されます。そのため、サイトへの暗黙的なアクセス権がある場合でも、ドメイン管理者は表示されません。
ロール
role 要素は、エンティティが持つことができるアクセスレベルを表します。gAcl:role 要素には次の 4 つの値を使用できます。
- reader - 閲覧者(読み取り専用アクセス権と同等)。
- writer - コラボレーター(読み取り/書き込みアクセス権と同等)。
- owner - 通常はサイト管理者(読み取り/書き込みアクセス権に相当)。
スコープ
スコープ要素は、このアクセスレベルを持つエンティティを表します。gAcl:scope 要素には次の 4 つのタイプがあります。
- user - メールアドレスの値(例: "user@gmail.com")。
- group - Google グループのメールアドレス(例: group@domain.com)。
- domain - Google Workspace ドメイン名(例: domain.com)。
- default - タイプ「default」のスコープは 1 つのみで、値はありません(例:
<gAcl:scope type="default">)。この特定のスコープは、パブリック サイトでユーザーがデフォルトで持つアクセス権を制御します。
注: ドメインの gAcl:role 値を「オーナー」アクセスに設定することはできません。リーダーまたは書き込み専用に設定できます。
ACL フィードの取得
AclFeed クラスと AclEntry クラスを使用して、サイトの共有権限を制御できます。これらのクラスは、サービスクラスの getFeed() メソッドを使用して取得できます。
次の例では、指定されたサイトの ACL フィードを取得し、各 AclEntry の権限を出力します。
public String getAclFeedUrl(String siteName) { String domain = "site"; // OR if the Site is hosted on G Suite, your domain (e.g. example.com) return "https://sites.google.com/feeds/acl/site/" + domain + "/" + siteName + "/"; } public void getAclFeed(String siteName) throws IOException, ServiceException { AclFeed aclFeed = client.getFeed(new URL(getAclFeedUrl(siteName)), AclFeed.class); for (AclEntry entry : aclFeed.getEntries()) { System.out.println(entry.getScope().getValue() + " (" + entry.getScope().getType() + ") : " + entry.getRole().getValue()); } } getAclFeed('my-site-name');
SiteFeed のエントリを操作している場合、各 SiteEntry には ACL フィードへのリンクが含まれています。たとえば、次のスニペットは SiteEntry の ACL フィードを取得します。
String aclLink = siteEntry.getLink(SitesAclFeedLink.Rel.ACCESS_CONTROL_LIST, Link.Type.ATOM).getHref(); AclFeed aclFeed = client.getFeed(new URL(aclLink), AclFeed.class);
サイトを共有する
注: 特定の共有 ACL は、ドメインでそのような権限が許可されている場合にのみ設定できます(例: G Suite ドメインでドメイン外の共有が有効になっている場合など)。
API を使用して Google サイトを共有するには、クライアントで新しい AclEntry を作成し、サーバーに POST する必要があります。
以下は、サイトの reader として「user@example.com」を追加する例です。
AclRole role = new AclRole("reader"); AclScope scope = new AclScope(AclScope.Type.USER, "user@example.com"); AclEntry aclEntry = addAclRole(role, scope, entry); public AclEntry addAclRole(AclRole role, AclScope scope, SiteEntry siteEntry) throws IOException, MalformedURLException, ServiceException { AclEntry aclEntry = new AclEntry(); aclEntry.setRole(role); aclEntry.setScope(scope); Link aclLink = siteEntry.getLink(SitesAclFeedLink.Rel.ACCESS_CONTROL_LIST, Link.Type.ATOM); return client.insert(new URL(aclLink.getHref()), aclEntry); }
指定可能な AclScope 値と AclRoles 値については、ACL フィードの概要セクションをご覧ください。
グループとドメインレベルの共有
サイトを 1 人のユーザーと共有する場合と同様に、Google グループまたは G Suite ドメイン全体でサイトを共有できます。
グループのメールアドレスで共有する場合:
AclScope scope = new AclScope(AclScope.Type.GROUP, "group_name@example.com");
ドメイン全体と共有する場合:
AclScope scope = new AclScope(AclScope.Type.DOMAIN, "example.com");
ドメイン単位での共有は、G Suite ドメインでのみ、サイトがホストされているドメインでのみサポートされます。たとえば、http://sites.google.com/a/domain1.com/siteA は、ドメイン 2.com ではなく、ドメイン 1.com とサイト全体を共有することしかできません。G Suite ドメインでホストされていないサイト(http://sites.google.com/site/siteB など)は、ドメインを招待できません。
共有権限の変更
サイトの既存の共有権限に対して、まず問題の AclEntry を取得し、必要に応じて権限を変更してから、AclEntry の update() メソッドを呼び出してサーバーの ACL を変更します。
この例では、サイトの共有セクションの前の aclEntry の例を変更し、'user@example.com' を writer(共同編集者)に更新します。
aclEntry.setRole(new AclRole("writer")); AclEntry updatedAclEntry = aclEntry.update(); // Could also use the client's update method // client.update(new URL(aclEntry.getEditLink().getHref()), aclEntry);
ETag について詳しくは、Google Data APIs リファレンス ガイドをご覧ください。
共有権限を削除する
共有権限を削除するには、まず AclEntry を取得し、その delete() メソッドを呼び出します。
aclEntry.delete(); // Could also use the client's delete method // client.delete(new URL(aclEntry.getEditLink().getHref()), aclEntry);
ETag について詳しくは、Google Data APIs リファレンス ガイドをご覧ください。
特別トピック
フィードまたはエントリを再度取得する
以前に取得したフィードまたはエントリを取得する場合は、前回取得したときから変更があった場合にのみリストまたはエントリを送信するようにサーバーに指示することで、効率を向上させることができます。
このような条件付き取得を行うために、getFeed() メソッドと getEntry() メソッドの両方で、ETag 値または If-Modified-Since ヘッダーの DateTime オブジェクトを受け入れる追加の引数が提供されています。エントリの etag には entry.getEtag() からアクセスできます。
この例では、コンテンツ ウェブページのエントリの条件付き取得を行います。
String feedUrl = "https://sites.google.com/feeds/content/site/siteName/123456789"; WebPageEntry entry = client.getEntry(new URL(feedUrl), WebPageEntry.class, "\"GVQHSARDQyp7ImBq\"");
サーバーは、このリクエストを受信すると、リクエストしたアイテムの ETag が指定した ETag と同じかどうかを確認します。ETag が一致する場合、アイテムは変更されておらず、サーバーは HTTP 304 を返すか、NotModifiedException 例外をスローします。
ETag が一致しない場合、アイテムは前回リクエストされてから変更されているため、サーバーはアイテムを返します。
ETag について詳しくは、Google Data APIs リファレンス ガイドをご覧ください。