Timeline: update

認証が必要です

設定されたタイムライン アイテムを更新します。例を見る

このメソッドは、/upload URI に対応し、次の特徴のメディアを受け入れます。

  • 最大ファイルサイズ: 10MB
  • 使用可能なメディア MIME タイプ: audio/*image/*video/*

リクエスト

HTTP リクエスト

このメソッドは、2 つの異なる URI を使用してメディア アップロード機能を提供します。詳しくは、メディア アップロードに関するドキュメントをご覧ください。

  • メディア アップロード リクエストのアップロード URI:
    PUT https://www.googleapis.com/upload/mirror/v1/timeline/id
  • メタデータ URI(メタデータのみのリクエスト):
    PUT https://www.googleapis.com/mirror/v1/timeline/id

パラメータ

パラメータ名 説明
パスパラメータ
id string タイムライン アイテムの ID。
必須のクエリ パラメータ
uploadType string /upload URI へのアップロード リクエストのタイプ。 有効な値は次のとおりです。
  • media - シンプルなアップロード。メタデータのないメディアのみをアップロードします。
  • multipart - マルチパート アップロード。1 つのリクエストでメディアとメタデータの両方をアップロードします。
  • resumable - 再開可能なアップロード。再開可能な方法でファイルをアップロードします。2 つ以上の連続するリクエストを使用します。最初のリクエストでメタデータを送信します。

承認

このリクエストは、少なくとも次のうち 1 つのスコープでの承認が必要です(認証と承認の詳細をご確認ください)。

範囲
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

リクエスト本文

リクエストの本文には、以下のプロパティをメタデータとしてタイムライン リソースを指定します。詳しくは、メディア アップロードに関するドキュメントをご覧ください。

プロパティ名 説明 備考
省略可能なプロパティ
bundleId string この商品アイテムのバンドル ID。サービスでは bundleId を指定して、多数のアイテムをグループ化できます。デバイス上の 1 つの最上位のアイテムの下に表示されます。 書き込み可能
canonicalUrl string タイムライン アイテムによって表されるデータの正規バージョンまたは高画質バージョンを指す正規 URL。 書き込み可能
creator nested object このアイテムを作成したユーザーまたはグループ。 書き込み可能
displayTime datetime このアイテムをタイムラインで表示したときに表示する時刻を、RFC 3339 の形式で指定します。ユーザーのタイムラインは、表示時間順に時系列の順に表示されます。これにより、タイムライン内でアイテムが表示される場所も決定されます。サービスによって設定されていない場合、表示時間はデフォルトで updated 時間になります。 書き込み可能
html string このアイテムの HTML コンテンツ。アイテムに texthtml の両方が指定されている場合、html がタイムラインにレンダリングされます。

許可されている HTML 要素 - これらの要素はタイムライン カードで使用できます。

  • ヘッダー: h1, h2, h3, h4, h5, h6
  • 画像: img
  • リスト: li, ol, ul
  • HTML5 セマンティクス: article, aside, details, figure, figcaption, footer, header, nav, section, summary, time
  • 構造: blockquote, br, div, hr, p, span
  • スタイル: b, big, center, em, i, u, s, small, strike, strong, style, sub, sup
  • テーブル: table, tbody, td, tfoot, th, thead, tr

ブロックされた HTML 要素: これらの要素とその内容は HTML ペイロードから削除されます。

  • ドキュメント ヘッダー: head, title
  • 埋め込み: audio, embed, object, source, video
  • フレーム: frame, frameset
  • スクリプト: applet, script

その他の要素: リストにない要素は削除されますが、その内容は保持されます。

書き込み可能
isBundleCover boolean この商品が一括販売商品かどうか

一括販売商品として指定された項目は、bundleId と同じ商品を含む一括販売商品へのエントリ ポイントとなります。メイン タイムラインにのみ表示されます。開いたバンドル内には表示されません

メインのタイムラインでは、次の項目が表示されます。
  • isBundleCovertrueに設定されているアイテム
  • bundleId のないアイテム
一括販売のサブタイムラインに表示される項目は次のとおりです。
  • 問題の bundleId isBundleCoverfalse に設定されているアイテム
書き込み可能
location nested object このアイテムに関連付けられている地域。 書き込み可能
notification nested object このアイテムに関する通知をデバイスに表示する方法を制御します。通知がない場合は、通知は生成されません。 書き込み可能
notification.deliveryTime datetime 通知の配信時刻。 書き込み可能
notification.level string 通知の重要度を示します。指定できる値は次のとおりです。
  • DEFAULT - デフォルトの重要度の通知。チャイムが鳴ってユーザーに警告します。
書き込み可能
recipients[] list このアイテムが共有されているユーザーまたはグループのリスト。 書き込み可能
sourceItemId string タイムライン アイテムを独自のサービス内のデータにマッピングするために使用できる不透明な文字列。 書き込み可能
speakableText string このアイテムのコンテンツの読み上げバージョン。READ_ALOUD メニュー項目とともに、このフィールドを使用して、読み上げたときによりクリアなテキストを表示するか、Glass で視覚的に表示されるものに関する詳細情報を提供します。

Glassware では、speechableType フィールドも指定する必要があります。これは、通知後にアイテムが読み上げられることをユーザーがリクエストした場合など、追加のコンテキストが役立つ場合に、このテキストの前に読み上げられます。
書き込み可能
speakableType string このアイテムのタイプに関する説明を表示します。通知の後でアイテムが読み上げられることをユーザーがリクエストした場合など、追加のコンテキストが役立つ場合は、アイテムの内容を読む前にユーザーに通知が届きます。

「メール」、「テキスト メッセージ」、「今日の惑星ニュースの更新」など、短い名詞句にする必要があります。

Glassware では、スピーディなテキストやテキストが含まれていない場合でも、タイムライン アイテムごとにこのフィールドに値を設定することをおすすめします。これにより、ユーザーは画面を見なくてもアイテムのタイプを把握できます。
書き込み可能
text string このアイテムのテキスト コンテンツ。 書き込み可能
title string このアイテムのタイトル。 書き込み可能

レスポンス

成功すると、このメソッドはレスポンスの本文で Timeline リソースを返します。

注: このメソッドで使用可能なコード例では、サポートされているプログラミング言語すべての例を示しているわけではありません(サポートされている言語の一覧については、クライアント ライブラリ ページをご覧ください)。

Java

Java クライアント ライブラリを使用します。

import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.NotificationConfig;
import com.google.api.services.mirror.model.TimelineItem;

import java.io.IOException;

public class MyClass {
  // ...

  /**
   * Update a timeline item in the user's Glass with an optional notification and attachment.
   * 
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item to update.
   * @param newText timeline item's text.
   * @param newNotificationLevel Optional notification level, supported values
   *        are {@code null} and "AUDIO_ONLY".
   * @return Updated timeline item on success, {@code null} otherwise.
   */
  public static TimelineItem updateTimelineItem(Mirror service, String itemId, String newText,
      String newNotificationLevel) {
    try {
      // First retrieve the timeline item from the API.
      TimelineItem timelineItem = service.timeline().get(itemId).execute();
      // Update the timeline item's metadata.
      timelineItem.setText(newText);
      if (newNotificationLevel != null && newNotificationLevel.length() > 0) {
        timelineItem.setNotification(new NotificationConfig().setLevel(newNotificationLevel));
      } else {
        timelineItem.setNotification(null);
      }
      return service.timeline().update(itemId, timelineItem).execute();
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
      return null;
    }
  }

  // ...
}

.NET

.NET クライアント ライブラリを使用します。

using System;
using System.IO;

using Google.Apis.Mirror.v1;
using Google.Apis.Mirror.v1.Data;

public class MyClass {
  // ...

  /// <summary>
  /// Update a timeline item in the user's Glass with an optional
  /// notification and attachment.
  /// </summary>
  /// <param name='service'>Authorized Mirror service.</param>
  /// <param name='itemId'>ID of the timeline item to update.</param>
  /// <param name='newText'>Timeline Item's text content.</param>
  /// <param name='newNotificationLevel'>
  /// Optional notification level, supported values are null and
  /// "AUDIO_ONLY".
  /// </param>
  /// <returns>
  /// Updated timeline item on success, null otherwise.
  /// </returns>
  public static TimelineItem UpdateTimelineItem(MirrorService service,
      String itemId, String newText, String newNotificationLevel) {
    try {
      // First retrieve the timeline item from the API.
      TimelineItem timelineItem = service.Timeline.Get(itemId).Fetch();
      // Update the timeline item's metadata.
      timelineItem.Text = newText;
      if (!String.IsNullOrEmpty(newNotificationLevel)) {
        timelineItem.Notification = new NotificationConfig() {
          Level = newNotificationLevel
        };
      } else {
        timelineItem.Notification = null;
      }
      return service.Timeline.Update(timelineItem, itemId).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
      return null;
    }
  }

  // ...
}

PHP

PHP クライアント ライブラリを使用します。

/**
 * Update a timeline item in the user's Glass with an optional
 * notification and attachment.
 *
 * @param Google_MirrorSservice $service Authorized Mirror service.
 * @param string $itemId ID of the timeline item to update.
 * @param string $newText timeline item's text (can be HTML content).
 * @param string $newNotificationLevel Optional notification level,
 *               supported values are {@code null} and "AUDIO_ONLY".
 * @return Google_TimelineItem Updated timeline item on success,
 *         null otherwise.
 */
function updateTimelineItem($service, $itemId, $newText, $newNotificationLevel) {
  try {
    $timelineItem = $service->timeline->get($itemId);
    $timelineItem->setText($newText);
    if ($notificationlevel != null) {
      $notification = new Google_NotificationConfig();
      $notification->setLevel($newNotificationLevel);
      $timelineItem->setNotification($notification);
    } else {
      $timelineItem->setNotification(null);
    }
    return $service->timeline->update($itemId, $timelineItem);
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
    return null;
  }
}

Python

Python クライアント ライブラリを使用します。

import io

from apiclient import errors
from apiclient.http import MediaIoBaseUpload
# ...

def update_timeline_item(service, item_id, new_text, 
                         new_notification_level=None):
  """Update a timeline item in the user's Glass.

  Args:
    service: Authorized Mirror service.
    item_id: ID of the timeline item to update.
    new_text: Timeline item's text (can be HTML content).
    new_content_type: Optional attachment's content type (supported content
                      types are 'image/*', 'video/*' and 'audio/*').
    new_attachment: Optional attachment as data string.
    new_notification_level: Optional notification level, supported values are
                            None and 'AUDIO_ONLY'.
  Returns:
    Updated timeline item on success, None otherwise.
  """
  try:
    # First retrieve the timeline item from the API.
    timeline_item = service.timeline().get(id=item_id).execute()
    # Update the timeline item's metadata.
    timeline_item['text'] = new_text
    if new_notification_level:
      timeline_item['notification'] = {'level': new_notification_level}
    elif 'notification' in timeline_item:
      timeline_item.pop('notification')
    return service.timeline().update(id=item_id, body=timeline_item).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
    return None

Ruby

Ruby クライアント ライブラリを使用します。

##
# Update a timeline item in the user's glass.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] item_id
#   ID of the timeline item to update.
# @param [String] new_text
#   Timeline item's new text.
# @param [String] new_notification_level
#   Optional new notification level, supported values are nil and 'AUDIO_ONLY'.
# @return [Google::APIClient::Schema::Mirror::V1::TimelineItem]
#   Updated timeline item instance if successful, nil otherwise.
def update_timeline_item(client, item_id, new_text, new_notification_level)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(
    :api_method => mirror.timeline.get,
    :parameters => { 'id' => item_id })
  if result.success?
    timeline_item = result.data
    timeline_item.text = new_text
    if new_notification_level
      timeline_item.notification = { 'level' => new_notification_level }
    else
      timeline_item.notification = nil
    end
    result = client.execute(
      :api_method => mirror.timeline.update,
      :body_object => timeline_item,
      :parameters => { 'id' => item_id })
    if result.success?
      return result.data
    end
  end
  puts "An error occurred: #{result.data['error']['message']}"
end

Go

Go クライアント ライブラリを使用します。

import (
	"code.google.com/p/google-api-go-client/mirror/v1"
	"fmt"
)

// UpdateTimelineItem updates a timeline item in the user's timeline with an
// optional notification and attachment.
func UpdateTimelineItem(g *mirror.Service, itemId string, newNotificationLevel string) (
	*mirror.TimelineItem, error) {
	t, err := g.Timeline.Get(itemId).Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	t.Text = newText
	if newNotificationLevel != "" {
		t.Notification = &mirror.NotificationConfig{Level: newNotificationLevel}
	} else {
		t.Notification = nil
	}
	r, err := g.Timeline.Update(itemId, t).Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	return r, nil
}

未加工の HTTP

クライアント ライブラリは使用しません。

PUT /mirror/v1/timeline/timeline item id HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer auth token
Content-Type: application/json
Content-Length: 26

{ "text": "Hello world" }