Java 言語ガイド

重要: このドキュメントは 2012 年より前に作成されたものです。認証オプション (OAuth 1.0、AuthSub、ClientLogin)が 正式にサポート終了となり です。Google Cloud 上の OAuth 2.0 に移行してください。

Google Sites Data API を使用すると、クライアント アプリケーションから Google サイト内のコンテンツへのアクセス、公開、変更を行うことができます。 クライアント アプリケーションでは、最近のアクティビティのリストをリクエストしたり、変更履歴を取得したり、添付ファイルをダウンロードしたりすることもできます。

このガイドでは、Sites Data API の機能に関する背景情報に加え、この API の使用例を紹介します。 Java クライアント ライブラリを使用します。クライアント ライブラリの設定については、 Google Data Java クライアント ライブラリ スタートガイドもし関心があるなら Java クライアント ライブラリが従来の Google サイト API とやり取りするために使用する基本プロトコルについて詳しくは、 プロトコル ガイドをご覧ください。

オーディエンス

このドキュメントは、Google サイトとやり取りするクライアント アプリケーションを作成するデベロッパーを対象としています。 Google Data Java クライアント ライブラリを使用します。

スタートガイド

Google サイトでは、認証に Google アカウントまたは G Suite アカウントを使用します。すでにアカウントをお持ちの場合は、準備は完了しています。 お持ちでない場合は、新しいアカウントを作成できます。

ライブラリのインストール

クライアント ライブラリの設定とインストールについては、Google Data Java クライアント ライブラリ スタートガイドをご覧ください。Eclipse を使用している場合、この記事では Google Data API Eclipse プラグインを使用してプロジェクトを設定する方法をご覧ください。利用を開始するには、以下が必要です。

  1. Java 1.5 以降をインストールする
  2. クライアント ライブラリをダウンロードするgdata-src.java.zip の最新バージョン)
  3. 依存関係のリストをダウンロードする
  4. サンプル アプリケーションgdata-samples.java.zip の最新バージョン)をダウンロードする

.jars をインストールしたら、プロジェクトに以下を含める必要があります。

  1. java/lib/gdata-sites-2.0.jar - ここでのバージョン 2.0 は、以前の Google サイト API のバージョン 1.4 を対象としています。
  2. java/lib/gdata-core-1.0.jar
  3. java/lib/gdata-client-1.0.jar
  4. java/lib/gdata-spreadsheet-3.0.jar(リストページ / リストアイテムを使用する場合)

また、依存関係 jar(gdata-media-1.0.jarmail.jargoogle-collect....jar)を必ず含めてください。

サンプル アプリケーションの実行

完全に機能するサンプル アプリケーションは、gdata-samples.java.zip ダウンロード ファイルの /java/sample/sites サブディレクトリにあります。 ソースは /trunk/java/sample/sites/ でも入手できます。 [Source] タブからアクセスできる SVN リポジトリ。SitesDemo.java では、従来の Google サイト API の使い方を示すさまざまな操作を行えます。

サンプルを実行するには、java/sample/util/lib/sample-util.jar を含める必要があります。

独自のプロジェクトを開始する

ヒント: Eclipse プラグインを簡単にセットアップする方法については、Eclipse と Google Data API の使用の記事をご覧ください。

アプリケーションのニーズに応じて、複数のインポートが必要になります。次のインポートから始めることをおすすめします。

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.*;

次に、以前の Google サイト API へのクライアント接続を表す SitesService オブジェクトを設定する必要があります。

SitesService client = new SitesService("yourCo-yourAppName-v1");

applicationName 引数は company-applicationname-version の形式にする必要があります。このパラメータはロギングの目的で使用されます。

: このガイドの残りの部分では、変数 clientSitesService が作成済みであることを前提としています。

以前の Google サイト API に対する認証

Java クライアント ライブラリは、公開フィードまたは非公開フィードの操作に使用できます。Site Data API では、Google ドキュメント、スプレッドシート、 Google サイトの権限や実行しようとしている操作によって異なります。たとえば、Google Chat のコンテンツ フィードを 更新は行わない場合、認証されたクライアントが必要になります。これを行うには、 ClientLogin のユーザー名/パスワード認証、AuthSub、または OAuth

AuthSub、OAuth、ClientLogin の詳細については、Google Data API の認証の概要をご覧ください。

ヒント: この API は SSL(HTTPS)をサポートしています。AuthSub/OAuth を使用する場合は、 SSL 経由のフィードをリクエストするには、https://sites.google.com/feeds/ のスコープを設定します。また、 [SSL を必須にする] オプションを有効にすると、API では、管理コントロール パネルの設定が適用されます。すべてのエンドポイントを client.useSsl(); を呼び出して、HTTPS 経由で API リクエストを送信します。

ウェブ アプリケーション用の AuthSub

ウェブ アプリケーション用の AuthSub 認証は、 認証する必要があります。オペレーターは、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 の使用をご覧ください。

セッション トークンの取り消し

Google Data API クライアント ライブラリでの AuthSub の使用をご覧ください。

ウェブ アプリケーションまたはインストール/モバイル アプリケーション用の OAuth

OAuth は、AuthSub の代わりに使用できるもので、ウェブ アプリケーション向けです。 OAuth は、AuthSub のセキュア モードおよび登録済みモードの使用に類似しています。 すべてのデータ リクエストにデジタル署名を施し、ドメインを登録する必要があります。

インストールされているアプリケーションに OAuth を組み込む手順を確認する

リクエスト トークンの取得

Google Data API クライアント ライブラリで OAuth を使用するをご覧ください。

リクエスト トークンの承認

Google Data API クライアント ライブラリで OAuth を使用するをご覧ください。

アクセス トークンへのアップグレード

Google Data API クライアント ライブラリで OAuth を使用するをご覧ください。

インストール済みアプリケーション/モバイル アプリケーション用の ClientLogin

ClientLogin は、インストールが必要なアプリケーションまたはモバイルアプリで使用します。 認証する必要があります。初回実行時に、アプリケーションはユーザーにユーザー名とパスワードの入力を求めます。後続のリクエストで 認証トークンが参照されます。

インストールしたアプリケーションに ClientLogin を組み込む手順を確認する

ClientLogin を使用するには、次のコマンドを呼び出します。 setUserCredentials() 継承される SitesService オブジェクトのメソッド GoogleService。ユーザーのメールアドレスとパスワードを指定します。 どのクライアントに代わってリクエストを行っているかがわかります例:

SitesService client = new SitesService("yourCo-yourAppName-v1");
client.setUserCredentials("example@gmail.com", "pa$$word");

ヒント: アプリケーションでのユーザーの初回認証が正常に完了したら、認証トークンを 後で使用するために呼び出します。アプリケーションを実行するたびにユーザーにパスワードの入力を求める必要はありません。 詳しくは、認証トークンのリコールをご覧ください。

Java アプリケーションで ClientLogin を使用する方法の詳細については、Google Data API クライアント ライブラリでの ClientLogin の使用をご覧ください。

トップへ戻る

サイト フィード

サイトフィードを使用すると、ユーザーが所有する Google サイト、または閲覧権限のある Google サイトを一覧表示できます。 また、既存のサイトの名前を変更する場合にも使用できます。G Suite ドメインの場合は、ドメイン エイリアス IP アドレス できます。

サイトの一覧表示

サイトフィードをクエリするには、HTTP GET をサイトフィードの URL に送信します。

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 ドメインでのみご利用いただけます。

サイトのコピーは、新しいサイトを作成するのと似ています。違いは、すべての Pod に 複製するサイトのセルフリンクを含む、新しい 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 つ以上のプロパティを変更してから、SiteEntryupdate() メソッドを呼び出します。 次の例では、以前のサイトのテーマを変更し、サイトの名前を変更しています。

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://www.mydomainsite.com http://sites.google.com/a/domain.com/mysite の代わりに使用できます。サイトがホストされている場所によっては、 サイトのウェブアドレスのマッピングを作成します。詳しくは、ヘルプセンターの記事をご覧ください。

サイトのウェブアドレスのマッピングを取得する

サイトのウェブアドレスのマッピングを返すには、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 として表示されます。たとえば、上記の例で、 サイトを参照する 3 つの webAddressMapping がある http://sites.google.com/site/myOtherTestSite

ウェブアドレスのマッピングを変更する

: GET/POST/PUT 操作はすべて、作業時に with-mappings=true パラメータを指定する必要があります。 いくつかご紹介しますパラメータが存在しない場合、webAddressMapping はサイトエントリ(GET)で返されることも、考慮もされません。 エントリからマッピングを更新/削除(PUT)するときに、

マッピングを追加、更新、削除するには、新しいサイトを作成するときに、該当するリンクを指定、変更、削除します。 サイトのメタデータの更新。サイトフィードの URI には、with-mappings=true パラメータを含める必要があります。 注: アドレスのマッピングを更新するには、サイト管理者であるか、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();

ウェブアドレスのマッピングは、サイトの作成時またはコピー時に指定することもできます。

トップへ戻る

アクティビティ フィード

アクティビティ フィードを取得することで、サイトの最近のアクティビティ(変更)を取得できます。Deployment の各エントリは、 アクティビティ フィードには、サイトに加えられた変更に関する情報が含まれます。

アクティビティ フィードをクエリするには、HTTP GET をアクティビティ フィードの URL に送信します。

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
フィード パラメータ説明
sitesite」または G Suite でホストされているドメインのドメイン(例: example.com)です。
siteNameサイトのウェブスペース名(例: 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 から継承: ListItemEntryListPageEntryAttachmentEntryWebAttachmentEntryFileCabinetPageEntryAnnouncementsPageEntryAnnouncementEntryWebPageEntryCommentEntry

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 クエリ パラメータの一部を使用してコンテンツ フィードを検索できます。 従来の Google サイト 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 を「,」で区切ります。この例では filecabinetlistpage 件のエントリ:

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 パラメータを使用してその特定のページを取得できます。 この例では、次の URL にあるページが返されます: 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、 ページ見出しが「新しいウェブページのタイトル」である。つまり、URL の <atom:title>new-webpage-title に正規化されます。 ページの URL パスをカスタマイズするには、<sites:pageName> 要素を設定します。

この例では、見出しが「File Storage」の新しい filecabinet ページが作成されていますが、 URL http://sites.google.com/site/siteName/files の下 (http://sites.google.com/site/siteName/file-storage の代わり) <sites:pageName> 要素を指定します。

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 パスが命名されます。

  1. <sites:pageName>(存在する場合)a-z, A-Z, 0-9, -, _ を満たす必要があります。
  2. <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が 表示されなくなります。通知のタイトルが「パーティー!!」に設定されています。コンテンツを「今週末」に表示することにしました

ページ テンプレート

ページ テンプレートの作成

ページ テンプレートを作成する手順は、新しいアイテム/ページを作成する場合と同じです。 サブページの作成。違いは category を追加し、用語とラベルを 'http://schemas.google.com/g/2005#template' に設定する点です。 「template」を使用します。

この例では、新しい 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);

テンプレートからページを作成する

ページ テンプレートを作成する場合と同様に、<link> を rel='http://schemas.google.com/sites/2008#template' で指定して、テンプレートから新しいページをインスタンス化できます。指差し ページテンプレートのセルフリンクに 追加することをおすすめします

この例では、新しい 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> を定義するテンプレート( の入力が必要です。また、<content> 要素を含めると、サーバーによって拒否されます。

ファイルのアップロード

Google サイトと同様に、API ではファイル キャビネット ページまたは親ページへの添付ファイルのアップロードをサポートしています。

添付ファイルを親にアップロードするには、コンテンツ フィードの URL に HTTP POST リクエストを送信します。

https://sites.google.com/feeds/content/site/siteName

添付ファイルの種類はすべて親ページにアップロードする必要があります。そのため、AttachmentEntry に親リンクを設定します。 またはアップロードしようとしている WebAttachmentEntry オブジェクト。詳細については、サブページの作成をご覧ください。

添付ファイルをアップロードしています

この例では、ユーザーのコンテンツ フィードで最初に見つかった FileCabinetPageEntry に PDF ファイルをアップロードします。 「Getting Started」というタイトルで添付ファイルが作成されます。(省略可)説明「HR パケット」を入力します。

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

ウェブ添付ファイル

ウェブ添付ファイルは特殊な種類の添付ファイルです。ウェブ上の他のファイルへのリンクです ファイルキャビネットのリスティングに追加できますこれは「URL でファイルを追加」機能に似ていますGoogle サイトの UI でアップロード方法を選択する。

: ウェブ添付ファイルはファイル キャビネット内でのみ作成できます。他のタイプのページにはアップロードできません。

この例では、ユーザーのコンテンツ フィードで見つかった最初の FileCabinetPageEntry の下に WebAttachmentEntry を作成します。 タイトルと説明(省略可)が「GoogleLogo」に設定されている「ナイスカラー」の 2 行になります

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() メソッドを使用します。これにより、HTTP PUT リクエストがエントリの edit に送信されます。 表示されます。

次の変更を加えて ListPageEntry を更新する例を次に示します。

  • タイトルが「更新後のタイトル」に変更されます。
  • ページの HTML コンテンツが「<p>更新された HTML コンテンツ</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);
}

この例では、HTTP PUT リクエストをエントリの edit-media リンクに送信します。返される AttachmentEntry には更新されたコンテンツが含まれます。

添付ファイルのメタデータとコンテンツの更新

添付ファイルのメタデータとそのコンテンツを同じ呼び出しで更新するには、updateMedia() メソッドを使用します。 ファイルの内容のみ、メタデータ、またはその両方を更新できる場合は、

この例では、添付ファイルのタイトルを「New Title」に変更し、説明を更新して、ファイルの内容を新しい .zip ファイルに置き換えます。 リクエストに新しいファイル コンテンツが含まれているため、AttachmentEntryupdateMedia() が使用されます。

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

エントリの edit リンクと ETag 値を渡すことで、サービスクラスの delete() メソッドを使用することもできます。

client.delete(entry.getEditLink().getHref(), "*"); // Note: using "*" may overwrite another client's changes.

エントリが正常に削除されると、サーバーは HTTP 200 OK を返します。

トップへ戻る



添付ファイルのダウンロード

AttachmentEntry をダウンロードするには、HTTP GET リクエストをエントリの content src リンクに送信します。

この例では、ユーザーのコンテンツ フィードで最初に見つかった 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 エントリは、特定のエンティティ(ユーザー、ユーザーのグループ、ドメイン、 デフォルト アクセス(一般公開サイト)でアクセスできます。明示的なアクセス権を持つエンティティに対してのみ、エントリが表示されます。1 つのエントリが表示されます。 [アクセス権を持つユーザー] のGoogle サイト UI の共有画面に表示されます。そのためドメイン管理者は表示されません 権限は付与されません。

ロール

role 要素は、エンティティが持つことができるアクセスレベルを表します。gAcl:role 要素で使用できる値は次の 4 つです。

  • reader — 閲覧者(読み取り専用アクセスと同等)。
  • writer — 共同編集者(読み取り/書き込みアクセスに相当)。
  • owner - 通常はサイト管理者(読み取り/書き込みアクセスに相当)。

スコープ

スコープ要素は、このアクセスレベルを持つエンティティを表します。gAcl:scope 要素には次の 4 つのタイプがあります。

  • user - メールアドレスの値(「user@gmail.com」など)。
  • group - Google グループのメールアドレス(例: group@domain.com)。
  • domain - G Suite のドメイン名(「domain.com」など)。
  • default - 「default」タイプのスコープが 1 つだけで、値はありません。 (例: <gAcl:scope type="default">)。この特定のスコープは、任意のユーザーがデフォルトで持つアクセスを制御します 公開サイトで公開されています

: ドメインに gAcl:role 値を指定することはできません。 「owner」に設定読み取りまたは書き込みのみ可能です

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 できます。

これは「user@example.com」を追加する場合の例です。サイトの reader として:

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 については、ACL フィードの概要セクションをご覧ください。 および AclRoles 値。

グループレベルおよびドメインレベルの共有

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 はドメイン全体を domain1.com とのみ共有でき、domain2.com とは共有できません。次のようなサイト G Suite ドメイン(例: http://sites.google.com/site/siteB)でホストされていないドメインは、ドメインを招待できません。

共有権限の変更

サイトの既存の共有権限を取得するには、まず問題の AclEntry を取得し、権限を変更します 次に、AclEntryupdate() メソッドを呼び出して、サーバー上の 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 API リファレンス ガイドをご覧ください。

共有権限の削除

共有権限を削除するには、まず AclEntry を取得してから、その delete() メソッドを呼び出します。

aclEntry.delete();

// Could also use the client's delete method
// client.delete(new URL(aclEntry.getEditLink().getHref()), aclEntry);

ETag の詳細については、Google Data API リファレンス ガイドをご覧ください。

トップへ戻る

特別なトピック

フィードまたはエントリの再取得

以前に取得したフィードやエントリを取得する場合は、次のように指示することで効率を向上させることができます。 リストまたはエントリが最後に取得されてから変更されている場合にのみ、サーバーに送信されるようになります。

このような条件付き取得を行うために、getFeed() メソッドと getEntry() メソッドの両方で、 If-Modified-Since ヘッダーの ETag 値または 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 が一致した場合、アイテムは変更されておらず、サーバーは HTTP 304 NotModifiedException 例外がスローされる。

ETag が一致しない場合、アイテムは前回のリクエスト以降に変更されているため、サーバーはアイテムを返します。

ETag の詳細については、Google Data API リファレンス ガイドをご覧ください。

トップへ戻る