Quantcast
Channel: kenji matsuokaのニッキ
Viewing all articles
Browse latest Browse all 342

Google Glass 開発者ガイド Subscriptions

$
0
0
Google Glass Subscriptionsを翻訳しました
Google Glass 開発者ガイド Timeline Google Glass 開発者ガイド 位置情報
目次
原文

Google Glass Subscriptions

Mirror APIはsubscribe to notifications(翻訳中)を可能とします。
それはTimeline item(翻訳中)上での特殊な操作や、ユーザーの位置情報が更新されたときに送信されます。

Notificationsを受信する

Mirror APIから送られるNotificationはsubscriptされたendpointへのPOSTリクエストとして、リクエストボディにJSONを含めて送られます。
HTTP

{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "UPDATE",
"userToken": "harold_penguin",
"verifyToken": "random_hash_to_verify_referer",
"userActions": [
{
"type": "<TYPE>",
"payload": "<PAYLOAD>"
}
]
}

Java

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.mirror.model.Notification;

import java.io.IOException;
import java.io.InputStream;
// ...

public class MyClass {
// ...

/**
* Parse a request body into a Notification object.
*
* @param requestBody The notification payload sent by the Mirror API.
* @return Parsed notification payload if successful, {@code null} otherwise.
*/
static Notification parseNotification(InputStream requestBody) {
try {
JsonFactory jsonFactory = new JacksonFactory();

return jsonFactory.fromInputStream(requetBody, Notification.class);
} catch (IOException e) {
System.out.println("An error occurred: " + e);
return null;
}
}

// ...
}

Python

import json

def parse_notification(request_body):
"""Parse a request body into a notification dict.

Params:
request_body: The notification payload sent by the Mirror API as a string.
Returns:
Dict representing the notification payload.
"""
return json.load(request_body)

あなたのサービスはエラーがなければ200 OKのステータスコードをAPIに返す必要があります。もし、エラーコードを返した場合、Mirror APIはあなたのサービスにNotificationを再送しようとするかもしれません。
注意:接続は10秒でタイムアウトになるため、長い処理が必要な場合はすぐにレスポンスを返して、長い処理は別スレッドで行ってください。

Notificationsのタイプ

Mirror APIは異なるイベントごとに異なるnotificationを送ってきます。
写真の共有

ユーザーがあなたのサービスに写真を共有したとき

{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "UPDATE",
"userToken": "harold_penguin",
"verifyToken": "random_hash_to_verify_referer",
"userActions": [
{
"type": "SHARE"
}
]
}

itemId属性は写真を含むitemのIDがセットされます。

{
"id": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"attachments": [
{
"contentType": "image/jpeg",
"id": "<ATTACHMENT_ID>",
"contentUrl": "https://www.googleapis.com/mirror/v1/attachments/3hidvm0xez6r8_dacdb3103b8b604_h8rpllg/<ATTACHMENT_ID>"
}
],
"recipients": [
{
"kind": "glass#contact",
"source": "api:<SERVICE_ID>",
"id": "<CONTACT_ID>",
"displayName": "<CONTACT_DISPLAY_NAME>",
"imageUrls": [
"<CONTACT_ICON_URL>"
]
}
]
}

注意 contactsと共有されれるcontentのより詳細な情報はContacts(翻訳中)をご覧下さい。

Reply

ビルドインのREPLY menu itemを使ってユーザーがTimeline itemに返信したとき

{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "INSERT",
"userToken": "harold_penguin",
"verifyToken": "random_hash_to_verify_referer",
"userActions": [
{
"type": "REPLY"
}
]
}

itemId属性には以下を含むitemのIDが設定されます。
・inReplyTo属性は返信されたTimeline itemのIDです
・text属性は返信されたテキストがセットされます。
・attachments属性はWebオーディオプレーヤーと録音された音声の音声ファイルがセットされます。
例:

{
"kind": "glass#timelineItem",
"id": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"inReplyTo": "3236e5b0-b282-4e00-9d7b-6b80e2f47f3d",
"text": "This is a text reply",
"attachments": [
{
"contentType": "text/vnd.google.audio-player-url",
"contentUrl": "<AUDIO_PLAYER_URL>"
},
{
"contentType": "text/vnd.google.audio-download-url",
"contentUrl": "<AUDIO_FILE_URL>"
}
]
}


削除

ユーザーがTimeline itemを削除したとき

{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "DELETE",
"userToken": "harold_penguin",
"verifyToken": "random_hash_to_verify_referer",
"userActions": [
{
"type": "DELETE"
}
]
}

itemId属性は削除したitemのIDがセットされます。これ以降アイテムはそのIDとisDeletedプロパティ以外のメタデータを保持しません。
Timelineからユーザーがアイテムを削除したら、あなたのシステムからもそのcontentを削除することをお勧めします。

カスタムMenu itemが選択されたとき

あなたのサービスが設定したカスタムMenu itemが選択されたとき

{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "UPDATE",
"userToken": "harold_penguin",
"userActions": [
{
"type": "CUSTOM",
"payload": "PING"
}
]
}

itemId属性にはユーザーが選択したmenu itemのIDがセットされます。

userAction配列にはユーザーがこのアイテムに対して行ったアクションのリストを含みます。

位置情報の更新

現在のユーザーの新しい位置情報が利用可能なとき

{
"collection": "locations",
"itemId": "latest",
"operation": "UPDATE",
"userToken": "harold_penguin",
"verifyToken": "random_hash_to_verify_referer"
}

Glasswareが位置情報の更新を受け取ったら、最新の位置情報を取得するためにglass.locations.getエンドポイントにリクエストを送って下さい。Glasswareは10分ごとに位置情報の更新を取得します。
注意 位置情報を調べるにはhttps://www.googleapis.com/auth/glass.locationの範囲が必要となります。


最終更新日2013年4月16日
Google Glass 開発者ガイド Timeline Google Glass 開発者ガイド 位置情報

Viewing all articles
Browse latest Browse all 342

Trending Articles