Timeline: update

ต้องมีการให้สิทธิ์

อัปเดตรายการในไทม์ไลน์ ดูตัวอย่าง

วิธีการนี้รองรับ 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 ที่อนุญาต - คุณใช้องค์ประกอบเหล่านี้ในการ์ดไทม์ไลน์ได้

  • ส่วนหัว: 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 เหมือนกับรายการนั้น โดยจะแสดงในไทม์ไลน์หลักเท่านั้น ไม่ใช่ภายในแพ็กเกจที่เปิด

ในไทม์ไลน์หลัก รายการที่แสดงคือ
  • รายการที่ตั้งค่า isBundleCover เป็น true
  • รายการที่ไม่มี bundleId
ในไทม์ไลน์ย่อยของแพ็กเกจ สิ่งที่จะแสดงมีดังนี้
  • รายการที่ตั้งค่า bundleId ที่เป็นปัญหา และ isBundleCover เป็น false
เขียนได้
location nested object สถานที่ตั้งทางภูมิศาสตร์ที่เชื่อมโยงกับรายการนี้ เขียนได้
notification nested object ควบคุมวิธีแสดงการแจ้งเตือนสําหรับรายการนี้ในอุปกรณ์ หากไม่พบ ระบบจะสร้างการแจ้งเตือน เขียนได้
notification.deliveryTime datetime เวลาในการส่งการแจ้งเตือน เขียนได้
notification.level string อธิบายว่าการแจ้งเตือนสําคัญแค่ไหน ค่าที่อนุญาตคือ
  • DEFAULT - การแจ้งเตือนความสําคัญเริ่มต้น เสียงกริ่งจะเล่นเพื่อแจ้งเตือนผู้ใช้
เขียนได้
recipients[] list รายชื่อผู้ใช้หรือกลุ่มที่มีการแชร์รายการนี้ด้วย เขียนได้
sourceItemId string สตริงทึบที่คุณใช้เพื่อจับคู่รายการไทม์ไลน์กับข้อมูลในบริการของคุณเอง เขียนได้
speakableText string เนื้อหาที่พูดได้ในรายการนี้ ในรายการเมนูของ READ_ALOUD ให้ใช้ช่องนี้เพื่อระบุข้อความที่จะชัดเจนขึ้นเมื่ออ่านออกเสียง หรือเพื่อให้ข้อมูลเพิ่มเติมเกี่ยวกับสิ่งที่แสดงใน Glass

Glassware ควรระบุช่อง SpeakableType ซึ่งจะพูดก่อนข้อความนี้ในกรณีที่บริบทเพิ่มเติมมีประโยชน์ เช่น เมื่อผู้ใช้ขอให้รายการนี้อ่านออกเสียงตามการแจ้งเตือน
เขียนได้
speakableType string คําอธิบายที่พูดได้ของประเภทรายการนี้ ระบบจะแจ้งให้ผู้ใช้ทราบก่อนที่จะอ่านเนื้อหาของรายการในกรณีที่บริบทเพิ่มเติมมีประโยชน์ เช่น เมื่อผู้ใช้ขอให้รายการดังกล่าวอ่านออกเสียงหลังจากการแจ้งเตือน

ควรเป็นวลีสั้นๆ ที่เรียบง่ายและเป็นคํานาม เช่น "อีเมล" "SMS" หรือ "การอัปเดตข่าวประจําวันของดาวเคราะห์"

เราขอแนะนําให้ใช้ Glassware เพื่อเติมข้อมูลในช่องนี้สําหรับทุกรายการในไทม์ไลน์ แม้ว่ารายการดังกล่าวจะไม่มี SpeakableText หรือ SMS เพื่อให้ผู้ใช้ได้เรียนรู้ประเภทของรายการโดยไม่ต้องดูหน้าจอ
เขียนได้
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

ใช้ไลบรารีของไคลเอ็นต์ 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" }