Requiere autorización
Actualiza un contacto en el lugar. Ve un ejemplo.
Solicitud
Solicitud HTTP
PUT https://www.googleapis.com/mirror/v1/contacts/id
Parámetros
Nombre del parámetro | Valor | Descripción |
---|---|---|
Parámetros de ruta de acceso | ||
id |
string |
El ID del contacto. |
Autorización
Esta solicitud requiere autorización con el siguiente alcance (obtén más información sobre la autenticación y la autorización).
Alcance |
---|
https://www.googleapis.com/auth/glass.timeline |
Cuerpo de la solicitud
En el cuerpo de la solicitud, proporciona un Recurso de contactos con las siguientes propiedades:
Nombre de la propiedad | Valor | Descripción | Notas |
---|---|---|---|
Propiedades obligatorias | |||
acceptCommands[].type |
string |
Es el tipo de operación al que corresponde este comando. Los valores permitidos son los siguientes:
|
admite escritura |
displayName |
string |
El nombre que se mostrará para este contacto. | admite escritura |
id |
string |
Es el ID de este contacto. La aplicación lo genera y se trata como un token opaco. | admite escritura |
imageUrls[] |
list |
Conjunto de URLs de imágenes que se muestran para un contacto. La mayoría de los contactos tienen una sola imagen, pero El contacto puede incluir hasta 8 URLs de imágenes, y se ajustará su tamaño y se recortará en un mosaico en el cliente. | admite escritura |
Propiedades opcionales | |||
acceptCommands[] |
list |
Es una lista de los comandos del menú por voz que puede controlar un contacto. Glass muestra hasta tres contactos para cada comando del menú por voz. Si hay más, se muestran los tres contactos con el priority más alto para ese comando en particular. |
admite escritura |
acceptTypes[] |
list |
Una lista de los tipos de MIME que admite un contacto. Se le mostrará el contacto al usuario si alguno de sus acceptTypes coincide con alguno de los tipos de archivos adjuntos del elemento. Si no se proporcionan AcceptTypes, se mostrará el contacto para todos los elementos. | admite escritura |
phoneNumber |
string |
Es el número de teléfono principal del contacto. Puede ser un número completamente calificado, con el código de país y el código de área, o un número local. | admite escritura |
priority |
unsigned integer |
Es la prioridad del contacto para determinar el orden en una lista de contactos. Los contactos con prioridades más altas se mostrarán antes que los que tengan prioridades más bajas. | admite escritura |
speakableName |
string |
Nombre de este contacto tal como se debe pronunciar. Si el nombre de este contacto debe pronunciarse como parte de un menú de desambiguación por voz, este nombre se utiliza como la pronunciación esperada. Esto es útil para los nombres de contactos con caracteres que no se pueden pronunciar o cuya ortografía no es fonética. | admite escritura |
type |
string |
Es el tipo de este contacto. Se usa para ordenar las IUs. Los valores permitidos son los siguientes:
|
admite escritura |
Respuesta
Si se aplica correctamente, este método muestra un recurso de contactos en el cuerpo de la respuesta.
Ejemplos
Nota: Los ejemplos de código disponibles para este método no representan todos los lenguajes de programación admitidos (consulta la página de bibliotecas cliente para consultar una lista de lenguajes admitidos).
Java
Usa la biblioteca cliente de 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
Usa la biblioteca cliente de .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
Utiliza la biblioteca cliente de 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
Utiliza la biblioteca cliente 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
Rita
Utiliza la biblioteca cliente de 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
Usa la biblioteca cliente de 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 sin procesar
No utiliza una biblioteca cliente.
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"] }