Contacts: update

승인 필요

연락처를 업데이트합니다. 예를 참조하세요.

요청

HTTP 요청

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

매개변수

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

승인

이 요청에는 다음 범위의 승인이 필요합니다(인증 및 승인 자세히 알아보기).

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

요청 본문

요청 본문에서는 다음과 같은 속성을 사용하여 Contacts 리소스를 제공합니다.

속성 이름 설명 참고
필수 속성
acceptCommands[].type string 이 명령어에 해당하는 연산 유형입니다. 허용되는 값은 다음과 같습니다.
  • TAKE_A_NOTE - '메모 작성' 음성 메뉴 명령어의 사용자 음성 스크립트가 포함된 타임라인 항목을 공유합니다.
  • POST_AN_UPDATE - '업데이트 게시' 음성 메뉴 명령어의 사용자 음성 스크립트가 포함된 타임라인 항목을 공유합니다.
쓰기 가능
displayName string 이 연락처에 표시할 이름입니다. 쓰기 가능
id string 이 연락처의 ID입니다. 애플리케이션에서 생성되며 불투명 토큰으로 취급됩니다. 쓰기 가능
imageUrls[] list 연락처에 표시할 이미지 URL 집합입니다. 대부분의 연락처에는 단일 이미지가 있지만 '그룹' 연락처에는 최대 8개의 이미지 URL이 포함될 수 있으며 클라이언트에서 크기가 조절되고 모자이크로 잘립니다. 쓰기 가능
선택적 속성
acceptCommands[] list 담당자가 처리할 수 있는 음성 메뉴 명령의 목록입니다. Glass에는 음성 메뉴 명령어당 최대 3개의 연락처가 표시됩니다. 그보다 많으면 특정 명령어에 관해 priority가 가장 높은 연락처 3개가 표시됩니다. 쓰기 가능
acceptTypes[] list 연락처에서 지원하는 MIME 유형의 목록입니다. 연락처의 수락 유형이 항목의 첨부파일 유형 중 하나와 일치하는 경우 연락처가 사용자에게 표시됩니다. acceptTypes가 지정되지 않으면 모든 항목에 연락처가 표시됩니다. 쓰기 가능
phoneNumber string 연락처의 기본 전화번호입니다. 국가 전화번호 및 지역 번호가 포함된 정규화된 전화번호 또는 현지 전화번호일 수 있습니다. 쓰기 가능
priority unsigned integer 연락처 목록에서 순서를 결정하는 연락처의 우선순위입니다. 우선순위가 높은 연락처가 우선순위가 낮은 연락처보다 먼저 표시됩니다. 쓰기 가능
speakableName string 이 연락처의 이름을 발음해야 합니다. 이 연락처의 이름을 음성 구분 메뉴의 일부로 말해야 하는 경우 이 이름이 예상 발음으로 사용됩니다. 이는 발음할 수 없는 문자가 있거나 표시 철자가 소리 나는 것이 아닌 연락처 이름에 유용합니다. 쓰기 가능
type string 이 연락처의 유형입니다. UI에서 정렬하는 데 사용됩니다. 허용되는 값은 다음과 같습니다.
  • INDIVIDUAL - 한 사람을 나타냅니다. 이는 기본값입니다.
  • GROUP - 두 명 이상을 나타냅니다.
쓰기 가능

응답

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

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

자바

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"]
}