ต้องมีการให้สิทธิ์
อัปเดตผู้ติดต่อที่มีอยู่ ดูตัวอย่าง
ส่งคำขอ
คำขอ HTTP
PUT https://www.googleapis.com/mirror/v1/contacts/id
พารามิเตอร์
| ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
|---|---|---|
| พารามิเตอร์เส้นทาง | ||
id |
string |
รหัสของผู้ติดต่อ |
การให้สิทธิ์
คำขอนี้ต้องได้รับการให้สิทธิ์ตามขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)
| ขอบเขต |
|---|
https://www.googleapis.com/auth/glass.timeline |
เนื้อหาของคำขอ
ในเนื้อหาคำขอ ให้ระบุทรัพยากรรายชื่อติดต่อพร้อมด้วยพร็อพเพอร์ตี้ต่อไปนี้
| ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | หมายเหตุ |
|---|---|---|---|
| พร็อพเพอร์ตี้ที่จำเป็น | |||
acceptCommands[].type |
string |
ประเภทการดำเนินการที่คำสั่งนี้สอดคล้องกับ ค่าที่ใช้ได้มีดังนี้
|
เขียนได้ |
displayName |
string |
ชื่อที่จะแสดงสำหรับรายชื่อติดต่อนี้ | เขียนได้ |
id |
string |
รหัสของรายชื่อติดต่อนี้ ซึ่งสร้างขึ้นโดยแอปพลิเคชันและถือว่าเป็นโทเค็นแบบทึบ | เขียนได้ |
imageUrls[] |
list |
ชุด URL รูปภาพที่จะแสดงสำหรับรายชื่อติดต่อ รายชื่อติดต่อส่วนใหญ่จะมีรูปภาพเดียว แต่มี "กลุ่ม" รายชื่อติดต่ออาจรวม URL รูปภาพได้สูงสุด 8 รายการ ซึ่งจะถูกปรับขนาดและครอบตัดเป็นภาพโมเสคบนไคลเอ็นต์ | เขียนได้ |
| พร็อพเพอร์ตี้ที่ไม่บังคับ | |||
acceptCommands[] |
list |
รายการคําสั่งเมนูเสียงที่ผู้ติดต่อจัดการได้ Glass จะแสดงรายชื่อติดต่อได้สูงสุด 3 รายการสำหรับคำสั่งเมนูเสียงแต่ละรายการ หากมีมากกว่านั้น รายชื่อติดต่อ 3 รายการที่มี priority สูงสุดจะปรากฏสำหรับคำสั่งนั้นโดยเฉพาะ |
เขียนได้ |
acceptTypes[] |
list |
รายการประเภท MIME ที่รายชื่อติดต่อรองรับ ระบบจะแสดงรายชื่อติดต่อต่อผู้ใช้หาก acceptTypes ใดๆ ตรงกับประเภทไฟล์แนบในรายการ หากไม่ได้ระบุacceptType รายชื่อติดต่อจะแสดงไว้สำหรับสินค้าทั้งหมด | เขียนได้ |
phoneNumber |
string |
หมายเลขโทรศัพท์หลักสำหรับรายชื่อติดต่อ หมายเลขนี้อาจเป็นหมายเลขที่สมบูรณ์ซึ่งมีรหัสการโทรระหว่างประเทศและรหัสพื้นที่ หรือหมายเลขท้องถิ่นก็ได้ | เขียนได้ |
priority |
unsigned integer |
ลำดับความสำคัญที่ผู้ติดต่อจะพิจารณาถึงการจัดลำดับในรายชื่อผู้ติดต่อ รายชื่อติดต่อที่มีลำดับความสำคัญสูงกว่าจะแสดงก่อนรายชื่อติดต่อที่มีลำดับความสำคัญต่ำกว่า | เขียนได้ |
speakableName |
string |
ชื่อของรายชื่อติดต่อนี้ตามที่ควรออกเสียง หากต้องพูดชื่อของผู้ติดต่อรายนี้เป็นส่วนหนึ่งของเมนูการชี้แจงด้วยเสียง ชื่อนี้จะใช้เป็นการออกเสียงที่คาดไว้ ซึ่งมีประโยชน์สำหรับชื่อผู้ติดต่อที่มีอักขระที่ออกเสียงไม่ได้ หรือการสะกดคำที่แสดงไม่ได้เป็นไปตามการออกเสียง | เขียนได้ |
type |
string |
ประเภทของรายชื่อติดต่อนี้ ซึ่งใช้สำหรับจัดเรียงใน UI ค่าที่ใช้ได้คือ
|
เขียนได้ |
คำตอบ
หากดำเนินการสำเร็จ วิธีการนี้จะแสดงทรัพยากรรายชื่อติดต่อในเนื้อหาการตอบกลับ
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
Java
import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Contact;
import java.io.IOException;
public class MyClass {
// ...
/**
* Rename an existing contact for the current user.
*
* @param service Authorized Mirror service.
* @param contactId ID of the contact to rename.
* @param newDisplayName New displayName for the contact.
* @return Patched contact on success, {@code null} otherwise.
*/
public static Contact renameContact(Mirror service, String contactId, String newDisplayName) {
try {
// Get the latest version of the contact from the API.
Contact contact = service.contacts().get(contactId).execute();
contact.setDisplayName(newDisplayName);
// Send an update request to the API.
return service. contacts().update(contactId, contact).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>
/// Rename an existing contact for the current user.
/// </summary>
/// <param name='service'>Authorized Mirror service.</param>
/// <param name='contactId'>ID of the contact to rename.</param>
/// <param name='newDisplayName'>
/// New displayName for the contact.
/// </param>
/// <returns>
/// Updated contact on success, null otherwise.
/// </returns>
public static Contact RRenameContact(MirrorService service,
String contactId, String newDisplayName) {
try {
Contact contact = service.Contacts.Get(contactId).Fetch();
contact.DisplayName = newDisplayName;
return service.Contacts.Update(contact, contactId).Fetch();
} catch (Exception e) {
Console.WriteLine("An error occurred: " + e.Message);
return null;
}
}
// ...
}
PHP
/**
* Rename an existing contact for the current user.
*
* @param Google_MirrorService $service Authorized Mirror service.
* @param string $contactId ID of the contact to rename.
* @param string $newDisplayName New displayName for the contact.
* @return Google_Contact Updated contact on success, null otherwise.
*/
function renameContact($service, $contactId, $newDisplayName) {
try {
$updatedContact = $service->contacts->get($contactId);
$updatedContact->setDisplayName($newDisplayName);
return $service->contacts->update($contactId, $updatedContact);
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
return null;
}
}
Python
from apiclient import errors
# ...
def rename_contact(service, contact_id, new_display_name):
"""Rename an existing contact for the current user.
Args:
service: Authorized Mirror service.
contact_id: ID of the contact to rename.
new_display_name: New displayName for the contact.
Returns:
return Patched contact on success, None otherwise.
"""
try:
# Get the latest version of the contact from the API.
contact = service.contacts().get(contact_id).execute()
contact['displayName'] = new_display_name
return service. contacts().update(
id=contact_id, body=contact).execute()
except errors.HttpError, e:
print 'An error occurred: %s' % error
return None
Ruby
##
# Rename an existing contact for the current user.
#
# @param [Google::APIClient] client
# Authorized client instance.
# @param [String] contact_id
# ID of the contact to rename.
# @param [String] new_display_name
# New displayName for the contact.
# @return [Google::APIClient::Schema::Mirror::V1::Contact]
# Updated contact on success, nil otherwise.
def rename_contact(client, contact_id, new_display_name)
mirror = client.discovered_api('mirror', 'v1')
# Get the latest version of the contact from the API.
result = client.execute(
:api_method => mirror.contacts.get,
:parameters => { 'id' => contact_id })
if result.success?
contact = result.data
contact.display_name = new_display_name
result = client.execute(
:api_method => mirror.contacts.update,
:parameters => { 'id' => contact_id },
:body_object => contact)
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"
)
// RenameContact renames an existing contact for the current user.
func RenameContact(g *mirror.Service, contactId string,
newDisplayName string) (*mirror.Contact, error) {
s, err := g. Contacts.Get(contactId).Do()
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
return nil, err
}
s.DisplayName = newDisplayName
r, err := g.Contacts.Patch(contactId, s).Do()
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
return nil, err
}
return r, nil
}
HTTP ดิบ
ไม่ได้ใช้ไลบรารีของไคลเอ็นต์
PUT /mirror/v1/contacts/harold HTTP/1.1 Authorization: Bearer auth token Content-Type: application/json Content-Length: length { "displayName": "Harold Penguin", "imageUrls": ["https://developers.google.com/glass/images/harold.jpg"] }