अनुमति देना ज़रूरी है
नया संपर्क शामिल करता है. उदाहरण देखें.
अनुरोध
एचटीटीपी अनुरोध
POST https://www.googleapis.com/mirror/v1/contacts
अनुमति देना
इस अनुरोध के लिए नीचे दिए गए दायरे के साथ अनुमति की ज़रूरत है (पुष्टि करने और अनुमति देने के बारे में ज़्यादा पढ़ें).
दायरा |
---|
https://www.googleapis.com/auth/glass.timeline |
अनुरोध का मुख्य भाग
अनुरोध के मुख्य हिस्से में, इन प्रॉपर्टी के साथ संपर्क जानकारी दें:
प्रॉपर्टी का नाम | मान | ब्यौरा | नोट |
---|---|---|---|
ज़रूरी प्रॉपर्टी | |||
acceptCommands[].type |
string |
इस निर्देश से जुड़ी कार्रवाई का टाइप. स्वीकृत मान हैं:
|
लिखा जा सकता है |
displayName |
string |
इस संपर्क के लिए प्रदर्शित करने के लिए नाम. | लिखा जा सकता है |
id |
string |
इस संपर्क का आईडी. इसे ऐप्लिकेशन से जनरेट किया जाता है और इसे ओपेक टोकन माना जाता है. | लिखा जा सकता है |
imageUrls[] |
list |
किसी संपर्क को दिखाने के लिए इमेज के यूआरएल का सेट. ज़्यादातर संपर्कों में एक इमेज होगी, लेकिन "ग्रुप" होगा संपर्क में अधिकतम 8 चित्र URL शामिल हो सकते हैं और उनका आकार बदल कर क्लाइंट के आधार पर मोज़ेक में काट दिया जाएगा. | लिखा जा सकता है |
वैकल्पिक प्रॉपर्टी | |||
acceptCommands[] |
list |
वॉइस मेन्यू के निर्देशों की सूची, जिसे कोई संपर्क मैनेज कर सकता है. Glass हर ध्वनि मेनू आदेश के लिए तीन संपर्क दिखाता है. अगर इससे ज़्यादा हैं, तो उस खास निर्देश के लिए सबसे ज़्यादा priority वाले तीन संपर्क दिखाए जाते हैं. |
लिखा जा सकता है |
acceptTypes[] |
list |
ऐसे MIME टाइप की सूची जिन्हें कोई संपर्क इस्तेमाल कर सकता है. अगर संपर्क का कोई भी प्रकार, आइटम पर मौजूद अलग-अलग तरह के अटैचमेंट से मेल खाता है, तो संपर्क उपयोगकर्ता को दिखाया जाएगा. अगर कोई ConsentType नहीं दिया गया है, तो सभी आइटम के लिए संपर्क दिखाया जाएगा. | लिखा जा सकता है |
phoneNumber |
string |
संपर्क का प्राथमिक फ़ोन नंबर. यह पूरी तरह क्वालिफ़ाइड नंबर, देश कॉलिंग कोड और एरिया कोड या कोई लोकल नंबर हो सकता है. | लिखा जा सकता है |
priority |
unsigned integer |
संपर्कों की सूची में क्रम तय करने के लिए संपर्क की प्राथमिकता. ज़्यादा प्राथमिकता वाले संपर्कों को, कम प्राथमिकता वाले संपर्कों से पहले दिखाया जाएगा. | लिखा जा सकता है |
speakableName |
string |
इस संपर्क का नाम, जिसका उच्चारण करना है. अगर इस संपर्क का नाम, आवाज़ साफ़ तौर पर बताने वाले मेन्यू के हिस्से के तौर पर बोला जाना चाहिए, तो इस नाम का इस्तेमाल उच्चारण के मुताबिक किया जाएगा. यह उन संपर्कों के नाम के लिए उपयोगी है जिनका कोई उच्चारण नहीं किया जा सकता या जिनकी डिसप्ले स्पेलिंग फ़ोनेटिक नहीं है. | लिखा जा सकता है |
type |
string |
इस संपर्क का प्रकार. इसका इस्तेमाल यूज़र इंटरफ़ेस (यूआई) में क्रम से लगाने के लिए किया जाता है. स्वीकृत मान हैं:
|
लिखा जा सकता है |
जवाब
कामयाब होने पर, यह तरीका जवाब के मुख्य हिस्से में संपर्क के लिए संसाधन दिखाता है.
उदाहरण
ध्यान दें: इस तरीके के लिए दिए गए कोड के उदाहरणों में इसके साथ काम करने वाली सभी प्रोग्रामिंग भाषाएं नहीं दिखाई गई हैं (इसके साथ काम करने वाली भाषाओं की सूची के लिए क्लाइंट लाइब्रेरी वाला पेज देखें).
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 क्लाइंट लाइब्रेरी का इस्तेमाल किया जाता है.
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 क्लाइंट लाइब्रेरी का इस्तेमाल किया जाता है.
/**
* 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 क्लाइंट लाइब्रेरी का इस्तेमाल किया जाता है.
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 क्लाइंट लाइब्रेरी का इस्तेमाल करता हो.
##
# 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
}
क्लाइंट लाइब्रेरी का इस्तेमाल नहीं करता.
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"]
}