ต้องมีการให้สิทธิ์
อัปเดตรายการในไทม์ไลน์ที่มีอยู่แล้ว ดูตัวอย่าง
วิธีนี้รองรับ URI /upload และยอมรับสื่อที่อัปโหลดซึ่งมีลักษณะเฉพาะต่อไปนี้
- ขนาดไฟล์สูงสุด: 10 MB
- ประเภท MIME ของสื่อที่ยอมรับมีดังนี้
audio/*image/*video/*
ส่งคำขอ
คำขอ HTTP
วิธีนี้จะทำให้มีฟังก์ชันการอัปโหลดสื่อผ่าน URI 2 แบบแยกกัน ดูรายละเอียดเพิ่มเติมได้ในเอกสารเกี่ยวกับการอัปโหลดสื่อ
- อัปโหลด URI สำหรับคำขออัปโหลดสื่อ:
PUT https://www.googleapis.com/upload/mirror/v1/timeline/id
- URI ข้อมูลเมตา สำหรับคำขอที่มีข้อมูลเมตาเท่านั้น:
PUT https://www.googleapis.com/mirror/v1/timeline/id
พารามิเตอร์
| ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
|---|---|---|
| พารามิเตอร์เส้นทาง | ||
id |
string |
รหัสของรายการในไทม์ไลน์ |
| พารามิเตอร์การค้นหาที่จำเป็น | ||
uploadType |
string |
ประเภทคำขออัปโหลดไปยัง URI /upload
ค่าที่ยอมรับได้ มีดังนี้
|
การให้สิทธิ์
คำขอนี้ต้องได้รับการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)
| ขอบเขต |
|---|
https://www.googleapis.com/auth/glass.timeline |
https://www.googleapis.com/auth/glass.location |
เนื้อหาของคำขอ
ในเนื้อหาคำขอ ให้ระบุทรัพยากรไทม์ไลน์ที่มีพร็อพเพอร์ตี้ต่อไปนี้เป็นข้อมูลเมตา ดูข้อมูลเพิ่มเติมได้จากเอกสารเกี่ยวกับการอัปโหลดสื่อ
| ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | หมายเหตุ |
|---|---|---|---|
| พร็อพเพอร์ตี้ที่ไม่บังคับ | |||
bundleId |
string |
รหัสชุดของสินค้านี้ บริการสามารถระบุ BundleId เพื่อจัดกลุ่มหลายรายการเข้าด้วยกันได้ โดยจะปรากฏใต้รายการระดับบนสุดรายการเดียวในอุปกรณ์ | เขียนได้ |
canonicalUrl |
string |
Canonical URL ที่ชี้ไปยังข้อมูลเวอร์ชัน Canonical/คุณภาพสูงที่แสดงโดยรายการในไทม์ไลน์ | เขียนได้ |
creator |
nested object |
ผู้ใช้หรือกลุ่มที่สร้างรายการนี้ | เขียนได้ |
displayTime |
datetime |
เวลาที่ควรจะแสดงเมื่อมีการดูรายการนี้ในไทม์ไลน์ ซึ่งอยู่ในรูปแบบ RFC 3339 ไทม์ไลน์ของผู้ใช้รายนี้จะจัดเรียงตามเวลาที่แสดง ดังนั้น วิธีนี้จึงเป็นตัวกำหนดตำแหน่งที่รายการจะแสดงในไทม์ไลน์ด้วย หากไม่ได้ตั้งค่าไว้โดยบริการ เวลาที่แสดงจะมีค่าเริ่มต้นเป็นเวลา updated |
เขียนได้ |
html |
string |
เนื้อหา HTML สำหรับรายการนี้ หากมีการระบุทั้ง text และ html สำหรับรายการหนึ่ง ระบบจะแสดง html ในไทม์ไลน์ องค์ประกอบ HTML ที่อนุญาต - คุณใช้องค์ประกอบเหล่านี้ในการ์ดไทม์ไลน์ได้
องค์ประกอบ HTML ที่ถูกบล็อก: องค์ประกอบเหล่านี้และเนื้อหาขององค์ประกอบจะถูกนำออกจากเพย์โหลด HTML
องค์ประกอบอื่นๆ: องค์ประกอบที่ไม่ได้ระบุจะถูกนำออก แต่เนื้อหาในองค์ประกอบนั้นยังคงอยู่ |
เขียนได้ |
isBundleCover |
boolean |
สินค้านี้เป็นปกแพ็กเกจหรือไม่ หากมีการทำเครื่องหมายสินค้าว่าเป็นหน้าปกแพ็กเกจ สินค้านั้นจะเป็นจุดแรกเข้าไปสู่กลุ่มสินค้าที่มี bundleId เหมือนกับสินค้าดังกล่าว ข้อมูลจะแสดงในไทม์ไลน์หลักเท่านั้น โดยไม่แสดงใน Bundle ที่เปิดไว้ในไทม์ไลน์หลัก รายการที่แสดงคือ
|
เขียนได้ |
location |
nested object |
สถานที่ตั้งทางภูมิศาสตร์ที่เชื่อมโยงกับรายการนี้ | เขียนได้ |
menuItems[] |
list |
รายการในเมนูที่จะปรากฏต่อผู้ใช้เมื่อเลือกรายการนี้ในไทม์ไลน์ | เขียนได้ |
menuItems[].action |
string |
ควบคุมลักษณะการทำงานเมื่อผู้ใช้เลือกตัวเลือกเมนู ค่าที่ใช้ได้คือ
|
เขียนได้ |
menuItems[].id |
string |
รหัสของรายการในเมนูนี้ โดยแอปพลิเคชันจะสร้างขึ้นและถือเป็นโทเค็นที่คลุมเครือ | เขียนได้ |
menuItems[].payload |
string |
เพย์โหลดทั่วไปที่ความหมายเปลี่ยนไปตามการดำเนินการของ MenuItem นี้
|
เขียนได้ |
menuItems[].removeWhenSelected |
boolean |
หากตั้งค่าเป็น "จริง" ในรายการในเมนู CUSTOM ระบบจะนำรายการนั้นออกจากเมนูหลังจากที่เลือก |
เขียนได้ |
menuItems[].values[] |
list |
สำหรับรายการ CUSTOM รายการค่าที่ควบคุมลักษณะที่ปรากฏของรายการในเมนูในแต่ละสถานะ ต้องระบุค่าสำหรับสถานะ DEFAULT หากสถานะของ PENDING หรือ CONFIRMED ขาดหายไป ระบบจะไม่แสดงสถานะเหล่านั้น |
เขียนได้ |
menuItems[].values[].displayName |
string |
ชื่อที่จะแสดงสำหรับรายการในเมนู หากคุณระบุพร็อพเพอร์ตี้นี้สำหรับรายการในเมนูในตัว คำสั่งเสียงตามบริบทเริ่มต้นสำหรับรายการในเมนูนั้นจะไม่แสดง | เขียนได้ |
menuItems[].values[].iconUrl |
string |
URL ของไอคอนที่จะแสดงพร้อมกับรายการในเมนู | เขียนได้ |
menuItems[].values[].state |
string |
สถานะที่ใช้ค่านี้ ค่าที่ใช้ได้คือ
|
เขียนได้ |
notification |
nested object |
ควบคุมวิธีแสดงการแจ้งเตือนสำหรับรายการนี้ในอุปกรณ์ หากไม่มี จะไม่มีการสร้างการแจ้งเตือน | เขียนได้ |
notification.deliveryTime |
datetime |
เวลาที่ควรส่งการแจ้งเตือน | เขียนได้ |
notification.level |
string |
อธิบายว่าการแจ้งเตือนมีความสำคัญเพียงใด ค่าที่ใช้ได้คือ
|
เขียนได้ |
recipients[] |
list |
รายชื่อผู้ใช้หรือกลุ่มที่มีการแชร์รายการนี้ด้วย | เขียนได้ |
sourceItemId |
string |
สตริงที่คลุมเครือซึ่งใช้เพื่อจับคู่รายการในไทม์ไลน์กับข้อมูลในบริการของคุณเองได้ | เขียนได้ |
speakableText |
string |
เนื้อหาแบบพูดได้ของรายการนี้ ใช้ฟิลด์นี้ร่วมกับรายการในเมนู READ_ALOUD เพื่อระบุข้อความที่จะชัดเจนขึ้นเมื่ออ่านออกเสียง หรือเพื่อเพิ่มข้อมูลขยายให้กับสิ่งที่แสดงเป็นภาพบน Glassกลาสแวร์ควรระบุช่อง SpeakableType ซึ่งจะพูดก่อนข้อความนี้ในกรณีที่บริบทเพิ่มเติมมีประโยชน์ เช่น เมื่อผู้ใช้ขอให้อ่านออกเสียงรายการหลังจากการแจ้งเตือน |
เขียนได้ |
speakableType |
string |
คำอธิบายประเภทของรายการนี้ที่พูดได้ โดยจะประกาศให้ผู้ใช้ทราบก่อนอ่านเนื้อหาของรายการในกรณีที่บริบทเพิ่มเติมมีประโยชน์ เช่น เมื่อผู้ใช้ขอให้อ่านออกเสียงรายการนั้นหลังจากการแจ้งเตือน ข้อมูลนี้ควรเป็นวลีคำนามสั้นๆ ง่ายๆ เช่น "อีเมล" "ข้อความ" หรือ "อัปเดตข่าวดาวเคราะห์รายวัน" เราขอแนะนำให้กลาสแวร์กรอกข้อมูลในช่องนี้สำหรับทุกรายการในไทม์ไลน์ แม้ว่ารายการนั้นจะไม่มีข้อความหรือข้อความที่พูดได้ เพื่อให้ผู้ใช้เรียนรู้ประเภทของรายการได้โดยไม่ต้องมองหน้าจอ |
เขียนได้ |
text |
string |
เนื้อหาข้อความของรายการนี้ | เขียนได้ |
title |
string |
ชื่อของรายการนี้ | เขียนได้ |
คำตอบ
หากสำเร็จ เมธอดนี้จะแสดงทรัพยากรไทม์ไลน์ในเนื้อหาการตอบกลับ
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
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
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
/**
* 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
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
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" }