Timeline: patch

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

อัปเดตรายการในไทม์ไลน์ที่มีอยู่แล้ว วิธีนี้รองรับแพตช์ความหมาย ดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

PATCH https://www.googleapis.com/mirror/v1/timeline/id

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
id string รหัสของรายการในไทม์ไลน์

การให้สิทธิ์

คำขอนี้ต้องได้รับการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

เนื้อหาของคำขอ

ในเนื้อหาคำขอ ให้ระบุส่วนที่เกี่ยวข้องของทรัพยากรไทม์ไลน์ตามกฎของแพตช์เชิงอรรถศาสตร์

คำตอบ

หากสำเร็จ เมธอดนี้จะแสดงทรัพยากรไทม์ไลน์ในเนื้อหาการตอบกลับ

ตัวอย่าง

หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)

Java.NETPHPPythonRubyGoHTTP ดิบ

ใช้ไลบรารีของไคลเอ็นต์ Java

import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.TimelineItem;

import java.io.IOException;

public class MyClass {
 
// ...

 
/**
   * Update the text of an existing timeline item.
   *
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item to update.
   * @param newText New text content for the timeline item.
   * @return Updated timeline item on success, {@code null} otherwise.
   */

 
public static TimelineItem patchTimelineItem(Mirror service, String itemId, String newText) {
   
TimelineItem patchedTimelineItem = new TimelineItem();
    patchedTimelineItem
.setText(newText);
   
try {
     
return service.timeline().patch(itemId, patchedTimelineItem).execute();
   
} catch (IOException e) {
     
System.err.println("An error occurred: " + e);
     
return null;
   
}
 
}

 
// ...
}

ใช้ไลบรารีของไคลเอ็นต์ .NET

using System;

using Google.Apis.Mirror.v1;
using Google.Apis.Mirror.v1.Data;

public class MyClass {
 
// ...

 
/// <summary>
 
/// Update the text of an existing timeline item.
 
/// </summary>
 
/// <param name='service'>Authorized Mirror service.</param>
 
/// <param name='itemId'>ID of the timeline item to update.</param>
 
/// <param name='newText'>
 
/// New text content for the timeline item.
 
/// </param>
 
/// <returns>
 
/// Updated timeline item on success, null otherwise.
 
/// </returns>
 
public static TimelineItem PatchTimelineItem(MirrorService service,
     
String itemId, String newText) {
   
TimelineItem patchedTimelineItem = new TimelineItem() {
     
Text = newText
   
};
   
try {
     
return service.Timeline.Patch(patchedTimelineItem, itemId).Fetch();
   
} catch (Exception e) {
     
Console.WriteLine("An error occurred: " + e.Message);
     
return null;
   
}
 
}

 
// ...
}

ใช้ไลบรารีของไคลเอ็นต์ PHP

/**
 * Update the text of an existing timeline item.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $itemId ID of the timeline item to update.
 * @param string $newText New text content for the timeline item.
 * @return Google_TimelineItem Updated timeline item on success,
 *         null otherwise.
 */

function patchTimelineItem($service, $itemId, $newText) {
 
try {
    $patchedTimelineItem
= new Google_TimelineItem();
    $patchedTimelineItem
->setText($text);
   
return $service->timeline->patch($itemId, $patchedTimelineItem);
 
} catch (Exception $e) {
   
print 'An error occurred: ' . $e->getMessage();
   
return null;
 
}
}

ใช้ไลบรารีของไคลเอ็นต์ Python

from apiclient import errors
# ...

def patch_timeline_item(service, item_id, new_text):
 
"""Update the text of an existing timeline item.

  Args:
    service: Authorized Mirror service.
    item_id: ID of the timeline item to update.
    new_text: New text content for the timeline item.

  Returns:
    Updated timeline item on success, None otherwise.
  """

  patched_timeline_item
= {'text': new_text}
 
try:
   
return service.timeline().patch(
        id
=item_id, body=patched_timeline_item).execute()
 
except errors.HttpError, error:
   
print 'An error occurred: %s' % error
   
return None

ใช้ไลบรารีของไคลเอ็นต์ Ruby

##
# Update the text of an existing Timeline Item.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] item_id
#   ID of the timeline item to update.
# @param [String] new_text
#   New text content for the timeline item.
# @return [Google::APIClient::Schema::Mirror::V1::TimelineItem]
#    Updated timeline item on success, nil otherwise.
def patch_timeline_item(client, item_id, new_text)
  mirror
= client.discovered_api('mirror', 'v1')
  result
= client.execute(
   
:api_method => mirror.timeline.patch,
   
:body_object => { 'text' => new_text },
   
:parameters => { 'id' => item_id })
 
if result.success?
   
return result.data
 
end
  puts
"An error occurred: #{result.data['error']['message']}"
end

ใช้ไลบรารีของไคลเอ็นต์ Go

import (
        "code.google.com/p/google-api-go-client/mirror/v1"
        "fmt"
)

// PatchTimelineItem updates the text of an existing timeline item.
func PatchTimelineItem(g *mirror.Service, itemId string, newText string) (
        *mirror.TimelineItem, error) {
        t := &mirror.TimelineItem{Text: newText}
        r, err := g.Timeline.Patch(itemId, t).Do()
        if err != nil {
                fmt.Printf("An error occurred: %v\n", err)
                return nil, err
        }
        return r, nil
}

ไม่ได้ใช้ไลบรารีของไคลเอ็นต์

PATCH /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" }