Google Glass Timelineを翻訳しました
<Google Glass Pythonクイックスタート|Google Glass Subscriptions>
目次
原文
Google Glass Timeline
Timeline itemでTimelineは分けられます。あなたはHTTP経由のRESTを使ってAPIでtimeline itemを挿入、管理できます。




注意Timeline itemは一週間ユーザーのGlassに残り、30日間MirrorAPIに残ります
簡単なTimeline itemを挿入する。
Insert(翻訳中)はTimeline itemをJSON representation of a timeline item(翻訳中)でREST endpointにポストします。多くのフィールドはオプションです。もっともシンプルなフォームは、短いメッセージのみを持つTimeline itemのコンテンツです。これはシンプルなtimeline itemを挿入する方法です。
HTTP
POST /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer {auth token}
Content-Type: application/json
Content-Length: 26
{ "text": "Hello world" }
Java
TimelineItem timelineItem = new TimelineItem();
timelineItem.setText("Hello world");
service.timeline().insert(timelineItem).execute();
Python
timeline_item = {'text': 'Hello world'}
service.timeline().insert(body=timeline_item).execute()
成功時にサーバーは作成したアイテムの完全なコピーとともに201レスポンスコードを作成し返します。
上記の例に対し成功のレスポンスは以下のようになります。
HTTP/1.1 201 Created
Date: Tue, 25 Sep 2012 23:30:11 GMT
Content-Type: application/json
Content-Length: 303
{
"kind": "glass#timelineItem",
"id": "1234567890",
"selfLink": "https://www.googleapis.com/mirror/v1/timeline/1234567890",
"created": "2012-09-25T23:28:43.192Z",
"updated": "2012-09-25T23:28:43.192Z",
"etag": "\"G5BI0RWvj-0jWdBrdWrPZV7xPKw/t25selcGS3uDEVT6FB09hAG-QQ\"",
"text": "Hello world"
}
挿入されたitemはユーザーのTimelineで以下のように見えます。

Timeline itemを読み込む
サービスはサービス自身が作成した全てのTimeline itemとサービスに対して共有された全てのTimeline itemにアクセスすることが出来ます。サービスでどのようにTimeline itemのlist(翻訳中)を読むかについて示します。
HTTP
POST /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer {auth token}
Content-Type: application/json
Content-Length: 26
{ "text": "Hello world" }
Java
TimelineItem timelineItem = new TimelineItem();
timelineItem.setText("Hello world");
service.timeline().insert(timelineItem).execute();
Python
timeline_item = {'text': 'Hello world'}
service.timeline().insert(body=timeline_item).execute()
成功時にサーバーは作成したアイテムの完全なコピーとともに201レスポンスコードを作成して返します。
上記の例の場合、成功時のレスポンスは以下のようになります。
HTTP
GET /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer {auth token}
Java
TimelineItem timelineItem = new TimelineItem();
service.timeline().list().execute();
Python
service.timeline().list().execute()
Timeline itemをGet(翻訳中) update(翻訳中) delete(翻訳中)するために他のREST操作を行うことも出来ます。
メディアを含むTimeline itemを挿入する
画像はたくさんの言葉以上に説得力があります。Timeline item上では余計にそうです。そのため画像や動画を添付したTimeline itemを挿入することも出来ます。低レベルな添付ファイルはHTTP multipartを使ってアップロードします。Google APIs client librariesでmedia uploadを使って簡単に行うことが出来ます。
添付付きのtimeline itemは以下のようになります。
HTTP
POST /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer {auth token}
Content-Type: multipart/related; boundary="mymultipartboundary"
Content-Length: {length}
--mymultipartboundary
Content-Type: application/json; charset=UTF-8
{ "text": "A solar eclipse of Saturn. Earth is also in this photo. Can you find it?" }
--mymultipartboundary
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
[binary image data]
--mymultipartboundary--
Java
Python
TimelineItem timelineItem = new TimelineItem();
timelineItem.setText("Hello world");
InputStreamContent mediaContent = new InputStreamContent(contentType, attachment);
service.timeline().insert(timelineItem, mediaContent).execute();
timeline_item = {'text': 'Hello world'}
media_body = MediaIoBaseUpload(
io.BytesIO(attachment), mimetype=content_type, resumable=True)
service.timeline().insert(body=timeline_item, media_body=media_body).execute()
画像が添付されたtimeline itemはグラスデバイスで以下のように見えます。

添付にアクセスする
添付があるTimeline itemはattachments(翻訳中)と呼ばれるプロパティの配列でそれらを出力します。添付のバイナリデータはcontentUrl(翻訳中)またはattachments endpoint(翻訳中)を通じて取得できます。
注意このコンテンツはOAuth2.0によってほかのAPI endpointsから保護されています。Google API Client librariesはメディアダウンロード機能を使って添付のバイナリコンテンツへのアクセスを提供します。
HTTP
GET /mirror/v1/timeline/{itemId}/attachments/{attachmentId} HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer {auth token}
Java
TimelineItem item = service.timeline().get(itemId).execute();
String attachmentId = item.getAttachments().get(0).getId();
service.attachments().get(itemId, attachmentId).executeAsInputStream();
Bundling cards

Bundlingにより多くの関係するcardをbundleに結合することが出来ます。Bundleは通常Timeline cardの右上がカールしていることで区別されます。



コンテンツをBudleするにはpagingとthreadingの二つの方法があります。
pagingはtimelineItem.htmlPages[](翻訳中)プロパティ内の値に記載されます。
paging bundleを使うなら全ての共有する要素は同じtimelineIdを使い、menu itemも同一のセットとしてください。これは一つのカード上に乗らないコンテンツをGlassに送るのに役立ちます。
Threadingは共通のbundleId(翻訳中)を持つ関連する多くのtimeline cardによってまとめられます。この方法では同一のbundleIdを持つtimeline itemを沢山作ります。もっとも新しく加えるitemはカバーカードです。このテクニックはメールのスレッドのように関連した情報に対して役立ちます
menu itemでユーザーと対話する
コンテンツを届けるのは出来ることの半分だけです。より対話的なサービスはユーザーからの問いかけにも答えます。ユーザーはmenu itemを選択することでTimeline cardに答えを返すことが出来ます。menu itemは二種類あります:ビルドインメニューアイテムとカスタムメニューアイテム
ビルドインメニューアイテムは timeline cardを読み上げたり、特定の場所までナビゲートしたり、画像を共有したりというGlassデバイスのハードウェアによって提供される特別な機能へのアクセスを提供します。
カスタムメニューアイテムはあなたのサービス特有の機能へのアクセスと関連するメニューアイコンを提供します。
ビルドインメニューアイテムを使う

timeline itemを挿入時にmenuItems array(翻訳中)を記載することでビルドインメニューアイテムを加えることが出来ます。
ビルドインアイテムを使うにはmenuItemのactionに含まれる値のみが使用可能です。
HTTP
HTTP/1.1 201 Created
Date: Tue, 25 Sep 2012 23:30:11 GMT
Content-Type: application/json
Content-Length: 303
{
"text": "Hello world",
"menuItems": [
{
"action": "REPLY"
}
]
}
注意:reference documentation(翻訳中)には利用可能なビルドインアクションの詳細が記載されています。
カスタムメニューアイテムを定義する
ビルドインアクションは十分でない可能性があります。多くのサービスではそれらサービス特有のmenu itemを表示する必要があります。
その場合はカスタムメニューアイテムを使うと良いでしょう。
カスタムメニューアイテムを作るには、menuItem.actionにCUSTOMと記載しmenuItem.idも記載します。
カスタムメニューアイテムの一つをユーザーが起動させた場合、notificationはあなたのサービスにmenuItem.idの値を送信します。これにより、何が通知されたかを特定できます。
あなたはグラスデバイスに表示されるためのiconUrlとdisplayNameが記載されたmenuItem.menuValueも含める必要があります。
HTTP
HTTP/1.1 201 Created
Date: Tue, 25 Sep 2012 23:30:11 GMT
Content-Type: application/json
Content-Length: 303
{
"text": "Hello world",
"menuItems": [
{
"action": "CUSTOM",
"id": "complete"
"values": [{
"displayName": "Complete",
"iconUrl": "http://example.com/icons/complete.png"
}]
}
]
}
注意:アイコンは透過な背景を持つ50pxの正方形なPNG画像が最適です。
ユーザーにtimeline cardのピン留めを許可する
あなたはtimeline cardをピン留めできるmenu itemを作ることが出来ます。それにより、timeline cardは常にメインの時計cardの左側に表示され続けます。同じmenu itemを使用して、ユーザーはピン留めを外すことも出来ます。ピン留めするmenu itemはビルドインメニューアイテムなので、必要なのはmenuItemsのaction(翻訳中)にTOGGLE_PINNEDを記載するだけです。
HTTP
HTTP/1.1 201 Created
Date: Tue, 25 Sep 2012 23:30:11 GMT
Content-Type: application/json
Content-Length: 303
{
"text": "You can pin or unpin this card.",
"menuItems": [
{
"action": "TOGGLE_PINNED"
}
...
]
}
最終更新日2013年4月16日
<Google Glass Pythonクイックスタート|Google Glass Subscriptions>