Contacts: patch

승인 필요

연락처를 업데이트합니다. 이 메서드는 패치 시맨틱스를 지원합니다. 예시 보기

요청

HTTP 요청

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

매개변수

매개변수 이름 설명
경로 매개변수
id string 연락처의 ID입니다.

확인할 내용

이 요청을 처리하려면 다음 범위의 승인을 받아야 합니다(인증 및 승인 자세히 알아보기).

범위
https://www.googleapis.com/auth/glass.timeline

요청 본문

요청 본문에서 패치 시맨틱스의 규칙에 따라 연락처 리소스의 관련 부분을 제공합니다.

응답

요청에 성공할 경우 이 메서드는 응답 본문에 Contacts 리소스를 반환합니다.

참고: 이 메서드에 제공되는 코드 예시가 지원되는 모든 프로그래밍 언어를 나타내는 것은 아닙니다. 지원되는 언어 목록은 클라이언트 라이브러리 페이지를 참조하세요.

자바

자바 클라이언트 라이브러리를 사용합니다.

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

.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

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

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

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

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

클라이언트 라이브러리를 사용하지 않습니다.

PATCH /mirror/v1/contacts/harold HTTP/1.1
Authorization: Bearer auth token
Content-Type: application/json
Content-Length: length

{
  "displayName": "Harold Penguin"
}