승인 필요
새 연락처를 삽입합니다. 예를 참조하세요.
요청
HTTP 요청
POST https://www.googleapis.com/mirror/v1/contacts
확인할 내용
이 요청을 처리하려면 다음 범위의 승인을 받아야 합니다(인증 및 승인 자세히 알아보기).
범위 |
---|
https://www.googleapis.com/auth/glass.timeline |
요청 본문
요청 본문에서는 다음과 같은 속성을 사용하여 Contacts 리소스를 제공합니다.
숙소 이름 | 값 | 설명 | 메모 |
---|---|---|---|
필수 속성 | |||
acceptCommands[].type |
string |
이 명령어에 해당하는 작업 유형입니다. 허용되는 값은 다음과 같습니다.
|
쓰기 가능 |
displayName |
string |
이 연락처에 표시할 이름입니다. | 쓰기 가능 |
id |
string |
이 연락처의 ID입니다. 애플리케이션에서 생성되고 불투명 토큰으로 처리됩니다. | 쓰기 가능 |
imageUrls[] |
list |
연락처에 표시할 이미지 URL 집합입니다. 대부분의 연락처는 하나의 이미지를 갖지만 '그룹' 연락처에는 최대 8개의 이미지 URL이 포함될 수 있으며, 해당 연락처의 크기가 조정되고 클라이언트에서 모자이크로 잘립니다. | 쓰기 가능 |
선택 속성 | |||
acceptCommands[] |
list |
연락처가 처리할 수 있는 음성 메뉴 명령어의 목록입니다. Glass에서는 음성 메뉴 명령어당 최대 3개의 연락처를 표시합니다. 이보다 더 많은 경우 특정 명령어에 priority 이 가장 높은 세 개의 연락처가 표시됩니다. |
쓰기 가능 |
acceptTypes[] |
list |
연락처에서 지원하는 MIME 유형 목록입니다. 수락 유형이 항목의 첨부파일 유형과 일치하는 경우 연락처가 사용자에게 표시됩니다. allowType을 지정하지 않으면 연락처가 모든 항목에 표시됩니다. | 쓰기 가능 |
phoneNumber |
string |
연락처의 기본 전화번호입니다. 국가 번호 및 지역 번호가 포함된 정규화된 전화번호 또는 지역 전화번호일 수 있습니다. | 쓰기 가능 |
priority |
unsigned integer |
연락처 목록에서 우선순위를 결정하는 연락처의 우선순위입니다. 우선순위가 높은 연락처는 우선순위가 낮은 연락처보다 먼저 표시됩니다. | 쓰기 가능 |
speakableName |
string |
이 연락처의 이름을 발음해야 합니다. 이 이름을 음성 명확성 메뉴의 일부로 사용해야 하는 경우 이 이름이 예상 발음으로 사용됩니다. 이 이름은 발음하기 어려운 문자가 있거나 표시 철자가 발음이 아닌 경우 연락처 이름에 유용합니다. | 쓰기 가능 |
type |
string |
이 연락처의 유형입니다. UI에서 정렬하는 데 사용됩니다. 허용되는 값은 다음과 같습니다.
|
쓰기 가능 |
응답
요청에 성공할 경우 이 메서드는 응답 본문에 Contacts 리소스를 반환합니다.
예
참고: 이 메서드에 제공되는 코드 예시가 지원되는 모든 프로그래밍 언어를 나타내는 것은 아닙니다. 지원되는 언어 목록은 클라이언트 라이브러리 페이지를 참조하세요.
자바
자바 클라이언트 라이브러리를 사용합니다.
import com.google.api.services.mirror.Mirror; import com.google.api.services.mirror.model.Contact; import java.io.IOException; import java.util.Arrays; public class MyClass { // ... /** * Insert a new contact for the current user. * * @param service Authorized Mirror service. * @param contactId ID of the contact to insert. * @param displayName Display name for the contact to insert. * @param iconUrl URL of the contact's icon. * @return The inserted contact on success, {@code null} otherwise. */ public static Contact insertContact(Mirror service, String contactId, String displayName, String iconUrl) { Contact contact = new Contact(); contact.setId(contactId); contact.setDisplayName(displayName); contact.setImageUrls(Arrays.asList(iconUrl)); try { return service.contacts().insert(contact).execute(); } catch (IOException e) { System.err.println("An error occurred: " + e); return null; } } // ... }
.NET
.NET 클라이언트 라이브러리를 사용합니다.
using System; using System.Collections.Generic; using Google.Apis.Mirror.v1; using Google.Apis.Mirror.v1.Data; public class MyClass { // ... /// <summary> /// Insert a new contact for the current user. /// </summary> /// <param name='service'>Authorized Mirror service.</param> /// <param name='contactId'>ID of the contact to insert.</param> /// <param name='displayName'> /// Display name for the contact to insert. /// </param> /// <param name='iconUrl'>URL of the contact's icon.</param> /// <returns> /// The inserted contact on success, null otherwise. /// </returns> public static Contact InsertContact(MirrorService service, String contactId, String displayName, String iconUrl) { Contact contact = new Contact() { Id = contactId, DisplayName = displayName, ImageUrls = new List<String>() {iconUrl} }; try { return service.Contacts.Insert(contact).Fetch(); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); return null; } } // ... }
PHP
PHP 클라이언트 라이브러리를 사용합니다.
/** * Insert a new contact for the current user. * * @param Google_MirrorService $service Authorized Mirror service. * @param string $contactId ID of the contact to insert. * @param string $displayName Display name for the contact to insert. * @param string $iconUrl URL of the contact's icon. * @return Google_Contact The inserted contact on success, null otherwise. */ function insertContact($service, $contactId, $displayName, $iconUrl) { try { $contact = new Google_Contact(); $contact->setId($contactId); $contact->setDisplayName($displayName); $contact->setImageUrls(array($iconUrl)); return $service->contacts->insert($contact); } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); return null; } }
Python
Python 클라이언트 라이브러리를 사용합니다.
from apiclient import errors
# ...
def insert_contact(service, contact_id, display_name, icon_url):
"""Insert a new contact for the current user.
Args:
service: Authorized Mirror service.
contact_id: ID of the contact to insert.
display_name: Display name for the contact to insert.
icon_url: URL of the contact's icon.
Returns:
The inserted contact on success, None otherwise.
"""
contact = {
'id': contact_id,
'displayName': display_name,
'imageUrls': [icon_url]
}
try:
service.contacts().insert(body=contact).execute()
except errors.HttpError, error:
print 'An error occurred: %s' % error
return None
Ruby
Ruby 클라이언트 라이브러리를 사용합니다.
## # Insert a new contact for the current user. # # @param [Google::APIClient] client # Authorized client instance. # @param [String] contact_id # ID of the contact to insert. # @param [String] display_name # Display name for the contact to insert. # @param [String] image_url # URL of the contact's icon. # @return [Google::APIClient::Schema::Mirror::V1::Contact] # The inserted contact on success, nil otherwise. def insert_contact(client, contact_id, display_name, image_url) mirror = client.discovered_api('mirror', 'v1') contact = mirror.contacts.insert.request_schema.new({ 'id' => contact_id, 'displayName' => display_name, 'imageUrls' => [image_url] }) result = client.execute( :api_method => mirror.contacts.insert, :body_object => contact) if result.success? return result.data else puts "An error occurred: #{result.data['error']['message']}" end end
Go
import ( "code.google.com/p/google-api-go-client/mirror/v1" "fmt" ) // InsertContact inserts a new contact for the current user. func InsertContact(g *mirror.Service, contactId string, displayName string, iconUrl string) (*mirror.Contact, error) { s := &mirror.Contact{ Id: contactId, DisplayName: displayName, ImageUrls: []string{iconUrl}, } r, err := g.Contacts.Insert(s).Do() if err != nil { fmt.Printf("An error occurred: %v\n", err) return nil, err } return r, nil }
원시 HTTP
클라이언트 라이브러리를 사용하지 않습니다.
POST /mirror/v1/contacts HTTP/1.1 Authorization: Bearer auth token Content-Type: application/json Content-Length: length { "id": "harold" "displayName": "Harold Penguin", "imageUrls": ["https://developers.google.com/glass/images/harold.jpg"] }