認証が必要です
新しい連絡先を挿入します。 例を見る。
リクエスト
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 のセット。ほとんどの連絡先には画像が 1 つしかなく、「グループ」は 1 つのみ連絡先には最大 8 つの画像の URL を含めることができます。この URL はクライアント上でサイズ変更され、モザイク状に切り抜かれます。 | 書き込み可能 |
| 省略可能なプロパティ | |||
acceptCommands[] |
list |
連絡先が処理できる音声コマンドのリスト。Glass では、音声コマンドごとに最大 3 件の連絡先が表示されます。5 件を超えると、その特定のコマンドについて priority の値が最も高い 3 つの連絡先が表示されます。 |
書き込み可能 |
acceptTypes[] |
list |
連絡先がサポートする MIME タイプのリスト。連絡先の acceptTypes のいずれかがアイテムの添付ファイルのタイプと一致する場合、連絡先はユーザーに表示されます。receiveTypes が指定されていない場合は、すべての項目について連絡先が表示されます。 | 書き込み可能 |
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;
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
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"] }