Contacts: patch
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Cần phải uỷ quyền
Cập nhật một người liên hệ tại chỗ. Phương thức này hỗ trợ ngữ nghĩa bản vá.
Xem ví dụ.
Yêu cầu
Yêu cầu HTTP
PATCH https://www.googleapis.com/mirror/v1/contacts/id
Thông số
Tên thông số |
Giá trị |
Mô tả |
Thông số đường dẫn |
id |
string |
Mã của người liên hệ.
|
Ủy quyền
Yêu cầu này yêu cầu uỷ quyền trong phạm vi sau (đọc thêm về việc xác thực và uỷ quyền).
Phạm vi |
https://www.googleapis.com/auth/glass.timeline |
Nội dung yêu cầu
Trong nội dung yêu cầu, hãy cung cấp các phần có liên quan của Tài nguyên danh bạ, theo quy tắc về ngữ nghĩa của bản vá.
Phản hồi
Nếu thành công, phương thức này sẽ trả về một Tài nguyên danh bạ trong nội dung phản hồi.
Ví dụ
Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).
Java
Sử dụng thư viện ứng dụng 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) {
Contact patchedContact = new Contact();
patchedContact.setDisplayName(newDisplayName);
try {
return service.contacts().patch(contactId, patchedContact).execute();
} catch (IOException e) {
System.err.println("An error occurred: " + e);
return null;
}
}
// ...
}
.NET
Sử dụng thư viện ứng dụng .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>
/// Patched contact on success, null otherwise.
/// </returns>
public static Contact RenameContact(MirrorService service,
String contactId, String newDisplayName) {
Contact patchedContact = new Contact() {
DisplayName = newDisplayName
};
try {
return service.Contacts.Patch(
patchedContact, contactId).Fetch();
} catch (Exception e) {
Console.WriteLine("An error occurred: " + e.Message);
return null;
}
}
// ...
}
PHP
Sử dụng thư viện ứng dụng 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 Patched contact on success, null otherwise.
*/
function renameContact($service, $contactId, $newDisplayName) {
try {
$patchedContact = new Google_Contact();
$patchedContact->setDisplayName($newDisplayName);
return $service->contacts->patch($contactId, $patchedContact);
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
return null;
}
}
Python
Sử dụng thư viện ứng dụng 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.
"""
patched_contact = {'displayName': new_display_name}
try:
return service.contacts().patch(
id=contact_id, body=patched_contact).execute()
except errors.HttpError, error:
print 'An error occurred: %s' % error
return None
Ruby
Dùng thư viện ứng dụng 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]
# Patched contact on success, nil otherwise.
def rename_contact(client, contact_id, new_display_name)
mirror = client.discovered_api('mirror', 'v1')
patched_contact = mirror.contacts.patch.request_schema.new({
'displayName' => new_display_name
})
result = client.execute(
:api_method => mirror.contacts.patch,
:parameters => { 'id' => contact_id },
:body_object => contact)
if result.success?
return result.data
else
puts "An error occurred: #{result.data['error']['message']}"
end
end
Go
Dùng Thư viện ứng dụng 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 := &mirror.Contact{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 thô
Không sử dụng thư viện ứng dụng.
PATCH /mirror/v1/contacts/harold HTTP/1.1
Authorization: Bearer auth token
Content-Type: application/json
Content-Length: length
{
"displayName": "Harold Penguin"
}
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2024-10-14 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-10-14 UTC."],[[["\u003cp\u003eUpdates an existing contact using patch semantics, allowing modification of specific fields.\u003c/p\u003e\n"],["\u003cp\u003eRequires authorization with the \u003ccode\u003ehttps://www.googleapis.com/auth/glass.timeline\u003c/code\u003e scope.\u003c/p\u003e\n"],["\u003cp\u003eThe request body should contain the desired changes to the contact, adhering to patch rules.\u003c/p\u003e\n"],["\u003cp\u003eSuccessful requests return the updated Contacts resource.\u003c/p\u003e\n"],["\u003cp\u003eProvides code examples in Java, .NET, PHP, Python, Ruby, Go, and Raw HTTP demonstrating contact updates.\u003c/p\u003e\n"]]],[],null,["# Contacts: patch\n\n**Requires [authorization](#auth)**\n\nUpdates a contact in place. This method supports [patch semantics](/glass/performance#patch).\n[See an example](#examples).\n\nRequest\n-------\n\n### HTTP request\n\n```\nPATCH https://www.googleapis.com/mirror/v1/contacts/id\n```\n\n### Parameters\n\n| Parameter name | Value | Description |\n|----------------|----------|------------------------|\n| **Path parameters** |||\n| `id` | `string` | The ID of the contact. |\n\n### Authorization\n\nThis request requires authorization with the following scope ([read more about authentication and authorization](/glass/authorization)).\n\n| Scope |\n|--------------------------------------------------|\n| `https://www.googleapis.com/auth/glass.timeline` |\n\n### Request body\n\nIn the request body, supply the relevant portions of a [Contacts resource](/glass/v1/reference/contacts#resource), according to the rules of patch semantics.\n\nResponse\n--------\n\nIf successful, this method returns a [Contacts resource](/glass/v1/reference/contacts#resource) in the response body.\n\nExamples\n--------\n\n**Note:** The code examples available for this method do not represent all supported programming languages (see the [client libraries page](/glass/tools-downloads/client-libraries) for a list of supported languages). \n\n### Java\n\nUses the [Java client library](/glass/tools-downloads/client-libraries). \n\n```java\nimport com.google.api.services.mirror.Mirror;\nimport com.google.api.services.mirror.model.Contact;\n\nimport java.io.IOException;\n\npublic class MyClass {\n // ...\n\n /**\n * Rename an existing contact for the current user.\n * \n * @param service Authorized Mirror service.\n * @param contactId ID of the contact to rename.\n * @param newDisplayName New displayName for the contact.\n * @return Patched contact on success, {@code null} otherwise.\n */\n public static Contact renameContact(Mirror service, String contactId, String newDisplayName) {\n Contact patchedContact = new Contact();\n patchedContact.setDisplayName(newDisplayName);\n\n try {\n return service.contacts().patch(contactId, patchedContact).execute();\n } catch (IOException e) {\n System.err.println(\"An error occurred: \" + e);\n return null;\n }\n }\n\n // ...\n}\n```\n\n### .NET\n\nUses the [.NET client library](/glass/tools-downloads/client-libraries). \n\n```css+lasso\nusing System;\n\nusing Google.Apis.Mirror.v1;\nusing Google.Apis.Mirror.v1.Data;\n\npublic class MyClass {\n // ...\n\n /// \u003csummary\u003e\n /// Rename an existing contact for the current user.\n /// \u003c/summary\u003e\n /// \u003cparam name='service'\u003eAuthorized Mirror service.\u003c/param\u003e\n /// \u003cparam name='contactId'\u003eID of the contact to rename.\u003c/param\u003e\n /// \u003cparam name='newDisplayName'\u003e\n /// New displayName for the contact.\n /// \u003c/param\u003e\n /// \u003creturns\u003e\n /// Patched contact on success, null otherwise.\n /// \u003c/returns\u003e\n public static Contact RenameContact(MirrorService service,\n String contactId, String newDisplayName) {\n Contact patchedContact = new Contact() {\n DisplayName = newDisplayName\n };\n try {\n return service.Contacts.Patch(\n patchedContact, contactId).Fetch();\n } catch (Exception e) {\n Console.WriteLine(\"An error occurred: \" + e.Message);\n return null;\n }\n }\n\n // ...\n}\n```\n\n### PHP\n\nUses the [PHP client library](/glass/tools-downloads/client-libraries). \n\n```php\n/**\n * Rename an existing contact for the current user.\n *\n * @param Google_MirrorService $service Authorized Mirror service.\n * @param string $contactId ID of the contact to rename.\n * @param string $newDisplayName New displayName for the contact.\n * @return Google_Contact Patched contact on success, null otherwise.\n */\nfunction renameContact($service, $contactId, $newDisplayName) {\n try {\n $patchedContact = new Google_Contact();\n $patchedContact-\u003esetDisplayName($newDisplayName);\n return $service-\u003econtacts-\u003epatch($contactId, $patchedContact);\n } catch (Exception $e) {\n print 'An error occurred: ' . $e-\u003egetMessage();\n return null;\n }\n}\n```\n\n### Python\n\nUses the [Python client library](/glass/tools-downloads/client-libraries). \n\n```python\nfrom apiclient import errors\n# ...\n\ndef rename_contact(service, contact_id, new_display_name):\n \"\"\"Rename an existing contact for the current user.\n\n Args:\n service: Authorized Mirror service.\n contact_id: ID of the contact to rename.\n new_display_name: New displayName for the contact.\n\n Returns:\n return Patched contact on success, None otherwise.\n \"\"\"\n patched_contact = {'displayName': new_display_name}\n try:\n return service.contacts().patch(\n id=contact_id, body=patched_contact).execute()\n except errors.HttpError, error:\n print 'An error occurred: %s' % error\n return None\n```\n\n### Ruby\n\nUses the [Ruby client library](/glass/tools-downloads/client-libraries). \n\n```ruby\n##\n# Rename an existing contact for the current user.\n#\n# @param [Google::APIClient] client\n# Authorized client instance.\n# @param [String] contact_id\n# ID of the contact to rename.\n# @param [String] new_display_name\n# New displayName for the contact.\n# @return [Google::APIClient::Schema::Mirror::V1::Contact]\n# Patched contact on success, nil otherwise.\ndef rename_contact(client, contact_id, new_display_name)\n mirror = client.discovered_api('mirror', 'v1')\n patched_contact = mirror.contacts.patch.request_schema.new({\n 'displayName' =\u003e new_display_name\n })\n result = client.execute(\n :api_method =\u003e mirror.contacts.patch,\n :parameters =\u003e { 'id' =\u003e contact_id },\n :body_object =\u003e contact)\n if result.success?\n return result.data\n else\n puts \"An error occurred: #{result.data['error']['message']}\"\n end\nend\n```\n\n### Go\n\nUses the [Go client library](/glass/tools-downloads/client-libraries). \n\n```go\nimport (\n \"code.google.com/p/google-api-go-client/mirror/v1\"\n \"fmt\"\n)\n\n// RenameContact renames an existing contact for the current user.\nfunc RenameContact(g *mirror.Service, contactId string,\n newDisplayName string) (*mirror.Contact, error) {\n s := &mirror.Contact{DisplayName: newDisplayName}\n r, err := g.Contacts.Patch(contactId, s).Do()\n if err != nil {\n fmt.Printf(\"An error occurred: %v\\n\", err)\n return nil, err\n }\n return r, nil\n}\n```\n\n### Raw HTTP\n\nDoes not use a client library. \n\n```http\nPATCH /mirror/v1/contacts/harold HTTP/1.1\nAuthorization: Bearer auth token\nContent-Type: application/json\nContent-Length: length\n\n{\n \"displayName\": \"Harold Penguin\"\n}\n```"]]