需要授權
更新聯絡人。 參閲範例。
要求
HTTP 要求
PUT https://www.googleapis.com/mirror/v1/contacts/id
參數
參數名稱 | 值 | 說明 |
---|---|---|
路徑參數 | ||
id |
string |
聯絡人的 ID。 |
授權
此要求需要以下範圍的授權 (進一步瞭解驗證和授權)。
範圍 |
---|
https://www.googleapis.com/auth/glass.timeline |
要求主體
在要求內容中,請提供聯絡資源並提供下列屬性:
資源名稱 | 值 | 說明 | Notes |
---|---|---|---|
必要屬性 | |||
acceptCommands[].type |
string |
這個指令所對應的作業類型。允許的值包括:
|
可寫入 |
displayName |
string |
此聯絡人的顯示名稱。 | 可寫入 |
id |
string |
此聯絡人的 ID。應用程式是由應用程式產生,而且會視為不透明的符記。 | 可寫入 |
imageUrls[] |
list |
聯絡人的聯絡圖片網址組合。大多數的聯絡人都有一張圖片,一個「群組」聯絡人最多可包含 8 個圖片網址,而會經過調整並裁剪成用戶端的馬賽克。 | 可寫入 |
選填屬性 | |||
acceptCommands[] |
list |
聯絡人可處理的語音選單指令清單。Glass 針對每個語音選單指令最多可顯示三個聯絡人。如果數量超過這個上限,系統會顯示該指令 priority 中三個最高的聯絡人。 |
可寫入 |
acceptTypes[] |
list |
聯絡人支援的 MIME 類型清單。只要聯絡人的 TypeType 與項目中的任何附件類型相符,系統就會向使用者顯示該聯絡人。如果您未提供接受類型,系統就會顯示所有聯絡人的聯絡人。 | 可寫入 |
phoneNumber |
string |
聯絡人的主要電話號碼。可以是完整的號碼,須包含國家/地區代碼與區碼或區碼。 | 可寫入 |
priority |
unsigned integer |
聯絡人的決定優先順序,以決定聯絡人清單中的排序。系統會優先顯示優先順序較高的聯絡人,優先顯示其優先順序較低的聯絡人。 | 可寫入 |
speakableName |
string |
此聯絡人名稱,應為發音。如果此聯絡人的名稱必須透過語音消除選單顯示,此名稱會用來當做預期發音。如果聯絡人名稱沒有發音,或是顯示拼音並非拼音,就很適合使用這個名稱。 | 可寫入 |
type |
string |
此聯絡人的類型。用於在 UI 中排序。允許的值包括:
|
可寫入 |
回應
如果成功,此方法會在回應主體中傳回 Contacts 資源。
範例
注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面。
Java
使用 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
使用 .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
使用 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
使用 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
使用 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
使用 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"] }