Fügt einen neuen Kontakt ein. Beispiel
Anfragen
HTTP-Anfrage
POST https://www.googleapis.com/mirror/v1/contacts
Autorisierung
Für diese Anfrage ist eine Autorisierung in folgendem Bereich erforderlich. Weitere Informationen zur Authentifizierung und Autorisierung
Umfang |
---|
https://www.googleapis.com/auth/glass.timeline |
Anfragetext
Geben Sie im Anfragetext eine Ressource vom Typ Contacts mit den folgenden Attributen an:
Attributname | Wert | Beschreibung | Hinweise |
---|---|---|---|
Erforderliche Properties | |||
acceptCommands[].type |
string |
Der Typ des Vorgangs, dem dieser Befehl entspricht. Zulässige Werte:
|
Bearbeitbar |
displayName |
string |
Der Name, der für diesen Kontakt angezeigt werden soll. | Bearbeitbar |
id |
string |
Eine ID für diesen Kontakt. Dieser wird von der Anwendung generiert und wird als intransparentes Token behandelt. | Bearbeitbar |
imageUrls[] |
list |
Bild-URLs, die für einen Kontakt angezeigt werden sollen. Die meisten Kontakte haben ein einzelnes Bild. Ein Kontakt aus der Gruppe kann aber bis zu acht Bild-URLs umfassen. Die Größe dieser Kontakte wird angepasst und auf dem Client in ein Mosaik zugeschnitten. | Bearbeitbar |
Optionale Attribute | |||
acceptCommands[] |
list |
Eine Liste von Sprachbefehlen, die ein Kontakt verarbeiten kann Glass zeigt bis zu drei Kontakte pro Sprachbefehl an. Wenn es mehr gibt, werden die drei Kontakte mit dem höchsten priority für diesen bestimmten Befehl angezeigt. |
Bearbeitbar |
acceptTypes[] |
list |
Eine Liste der MIME-Typen, die ein Kontakt unterstützt. Der Kontakt wird dem Nutzer angezeigt, wenn einer seiner akzeptierten Typen mit einem der Arten von Anhängen auf dem Element übereinstimmt. Wenn keine AcceptTypes angegeben werden, wird der Kontakt für alle Artikel angezeigt. | Bearbeitbar |
phoneNumber |
string |
Primäre Telefonnummer des Kontakts. Das kann eine voll qualifizierte Nummer mit Ländervorwahl und Vorwahl oder eine lokale Nummer sein. | Bearbeitbar |
priority |
unsigned integer |
Priorität für den Kontakt, um die Reihenfolge in der Kontaktliste festzulegen. Kontakte mit höherer Priorität werden vor Kontakten mit niedrigerer Priorität angezeigt. | Bearbeitbar |
speakableName |
string |
Name dieses Kontakts, wie er ausgesprochen werden sollte. Wenn der Name dieses Kontakts im Menü zur Sprachdeklaration gesprochen werden muss, wird dieser Name als erwartete Aussprache verwendet. Das ist hilfreich bei Kontaktnamen mit nicht aussprechenden Zeichen oder wenn ihre Schreibweise sonst nicht phonetisch ist. | Bearbeitbar |
type |
string |
Der Typ für diesen Kontakt. Wird zum Sortieren in Benutzeroberflächen verwendet. Zulässige Werte:
|
Bearbeitbar |
Antwort
Wenn der Vorgang erfolgreich ist, wird mit dieser Methode eine Ressource für Kontakte im Antworttext zurückgegeben.
Beispiele
Hinweis: Bei den für diese Methode verfügbaren Codebeispielen sind nicht alle unterstützten Programmiersprachen vertreten. Eine Liste der unterstützten Sprachen finden Sie auf der Seite für Clientbibliotheken.
Java
Verwendet die Java-Clientbibliothek.
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
Verwendet die .NET-Clientbibliothek.
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
Verwendet die PHP-Clientbibliothek.
/** * 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
Verwendet die Python-Clientbibliothek.
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
Verwendet die Ruby-Clientbibliothek.
## # 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
Einfach loslegen (Go)
Verwendet die Go-Clientbibliothek.
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 }
Rohes HTTP
Verwendet keine Clientbibliothek.
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"] }