需要授權
更新現有的時間軸項目。 請點選此處查看範例。
此方法支援 /upload URI,並接受具有下列特性的上傳媒體:
- 檔案大小上限:10 MB
- 接受的媒體 MIME 類型:
audio/*,image/*,video/*
要求
HTTP 要求
這個方法透過兩個獨立的 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 的上傳要求類型。 可接受的值為: |
授權
這項要求需要至少擁有下列其中一個範圍的授權 (進一步瞭解驗證和授權)。
| 範圍 |
|---|
https://www.googleapis.com/auth/glass.timeline |
https://www.googleapis.com/auth/glass.location |
要求主體
在要求主體中,提供時間軸資源並附上下列屬性,做為中繼資料。詳情請參閱媒體上傳相關文件。
| 屬性名稱 | 值 | 說明 | 附註 |
|---|---|---|---|
| 選用屬性 | |||
bundleId |
string |
這個項目的軟體包 ID。服務可以指定一個 bundleId,將多個商品歸為一組。這類素材資源會顯示在裝置上的單一頂層項目底下。 | 可寫入 |
canonicalUrl |
string |
指向時間軸項目所代表資料的標準/高品質版本標準網址。 | 可寫入 |
creator |
nested object |
建立這個項目的使用者或群組。 | 可寫入 |
displayTime |
datetime |
透過時間軸查看這個項目時應顯示的時間,採用 RFC 3339 格式。這位使用者的時間軸是依顯示時間先後排序,因此也會決定該項目在時間軸中的顯示位置。如果服務未設定,顯示時間會預設為 updated 時間。 |
可寫入 |
html |
string |
這個項目的 HTML 內容。如果同時為某個項目提供 text 和 html,系統會在時間軸中顯示 html。允許的 HTML 元素 - 您可以在時間軸資訊卡中使用這些元素。
封鎖的 HTML 元素:這些元素及其內容會從 HTML 酬載中移除。
其他元素:系統會移除未列出的元素,但保留其內容。 |
可寫入 |
isBundleCover |
boolean |
這項商品是否為套裝組合封面。 如果商品已標示為套裝組合封面,則系統會將該商品設為與該項目具有相同 bundleId 的項目組合的進入點。此圖表只會顯示在主要時間軸上,而「不會顯示在已開啟的套件中」。主要時間軸會顯示的項目如下:
|
可寫入 |
location |
nested object |
與這個項目相關聯的地理位置。 | 可寫入 |
menuItems[] |
list |
使用者在時間軸中選取這個項目時,會看到選單項目清單。 | 可寫入 |
menuItems[].action |
string |
控管使用者選取選單選項時的行為。允許的值包括:
|
可寫入 |
menuItems[].id |
string |
這個選單項目的 ID。這項資訊是由應用程式產生,並視為不透明權杖。 | 可寫入 |
menuItems[].payload |
string |
一般酬載,其意義會因此 MenuItem 的動作而異。
|
可寫入 |
menuItems[].removeWhenSelected |
boolean |
如果針對 CUSTOM 選單項目設為 true,選取後就會從選單移除。 |
可寫入 |
menuItems[].values[] |
list |
針對 CUSTOM 項目,這裡列出的值清單,用於控制選單項目在各個狀態下的外觀。必須提供 DEFAULT 狀態的值。如果缺少 PENDING 或 CONFIRMED 狀態,就不會顯示。 |
可寫入 |
menuItems[].values[].displayName |
string |
選單項目的顯示名稱。如果您為內建選單項目指定這個屬性,系統就不會顯示該選單項目的預設內容相關語音指令。 | 可寫入 |
menuItems[].values[].iconUrl |
string |
與選單項目一同顯示的圖示網址。 | 可寫入 |
menuItems[].values[].state |
string |
此值適用的狀態。允許的值包括:
|
可寫入 |
notification |
nested object |
控管這個項目的通知在裝置上的顯示方式。如果缺少這項資訊,系統就不會產生任何通知。 | 可寫入 |
notification.deliveryTime |
datetime |
傳送通知的時間。 | 可寫入 |
notification.level |
string |
說明通知的重要性。允許的值包括:
|
可寫入 |
recipients[] |
list |
可與這個項目共用的使用者或群組清單。 | 可寫入 |
sourceItemId |
string |
不透明字串,可用來將時間軸項目對應至自家服務中的資料。 | 可寫入 |
speakableText |
string |
這個項目的內容可朗讀版本。除了 READ_ALOUD 選單項目外,您也可以使用這個欄位提供清楚的文字,在大聲朗讀時要清楚辨識,或是針對 Glass 顯示的視覺內容提供延伸資訊。Glassware 也應指定 readableType 欄位,如果能提供其他背景資訊相當實用,例如在通知後朗讀項目,例如使用者要求系統朗讀該項目時,系統就會直接讀出該欄位。 |
可寫入 |
speakableType |
string |
這個項目的類型說明。若使用者要求系統朗讀某項商品時,在通知後建議系統朗讀該項目,系統會在使用者閱讀該項目內容前向他們宣布。 請使用簡短且簡單的名詞片語,例如「電子郵件」、「簡訊」或「每日星球新聞最新消息」。 我們鼓勵在每個時間軸項目填入這個欄位,即使該項目未包含 readableText 或文字,也能讓使用者不必查看螢幕就知道項目的類型。 |
可寫入 |
text |
string |
這個項目的文字內容。 | 可寫入 |
title |
string |
這個項目的標題。 | 可寫入 |
回應
如果成功,這個方法會在回應主體中傳回時間軸資源。
範例
注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面。
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 用戶端程式庫。
##
# 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" }