Nécessite une autorisation
Met à jour un contact en place. Voir un exemple.
Demande
Requête HTTP :
PUT https://www.googleapis.com/mirror/v1/contacts/id
Paramètres
Nom du paramètre | Valeur | Description |
---|---|---|
Paramètres de chemin d'accès | ||
id |
string |
ID du contact. |
Autorisation
Cette requête nécessite une autorisation ayant la portée suivante (en savoir plus sur l'authentification et l'autorisation).
Portée |
---|
https://www.googleapis.com/auth/glass.timeline |
Corps de la requête
Dans le corps de la requête, indiquez une ressource Contacts avec les propriétés suivantes:
Nom de propriété | Valeur | Description | Remarques |
---|---|---|---|
Propriétés obligatoires | |||
acceptCommands[].type |
string |
Type d'opération auquel cette commande correspond. Valeurs autorisées:
|
accessible en écriture |
displayName |
string |
Nom à afficher pour ce contact. | accessible en écriture |
id |
string |
ID de ce contact. Il est généré par l'application et traité comme un jeton opaque. | accessible en écriture |
imageUrls[] |
list |
Ensemble d'URL d'images à afficher pour un contact. La plupart des contacts ont une seule image, mais un contact "de groupe" peut comprendre jusqu'à 8 URL d'image, et ils seront redimensionnés et recadrés dans une mosaïque sur le client. | accessible en écriture |
Propriétés facultatives | |||
acceptCommands[] |
list |
Liste des commandes vocales de menu qu'un contact peut gérer. Glass affiche un maximum de trois contacts pour chaque commande vocale du menu. S'il y en a plus, les trois contacts ayant le priority le plus élevé sont affichés pour cette commande particulière. |
accessible en écriture |
acceptTypes[] |
list |
Liste des types MIME acceptés par un contact. Le contact sera affiché à l'utilisateur si l'un de ses AcceptTypes correspond à l'un des types de pièces jointes de l'élément. Si aucune valeur acceptéesTypes n'est définie, le contact sera affiché pour tous les éléments. | accessible en écriture |
phoneNumber |
string |
Numéro de téléphone principal du contact. Il peut s'agir d'un numéro complet avec l'indicatif de pays et l'indicatif de zone, ou un numéro local. | accessible en écriture |
priority |
unsigned integer |
Priorité pour le contact afin de déterminer l'ordre d'affichage dans une liste de contacts. Les contacts de priorité supérieure s'affichent avant ceux de priorité inférieure. | accessible en écriture |
speakableName |
string |
Nom de ce contact tel qu'il doit être prononcé. Si le nom de ce contact doit être prononcé dans un menu de sélection d'ambiguïté, ce nom sera utilisé pour la prononciation attendue. Cette option est utile pour les noms de contact comportant des caractères non prononcés ou dont l'orthographe n'est pas phonétique dans les autres cas. | accessible en écriture |
type |
string |
Type de ce contact. Cela permet de trier les interfaces utilisateur. Valeurs autorisées:
|
accessible en écriture |
Réponse
Lorsque cette méthode fonctionne, elle renvoie une ressource Contacts dans le corps de la réponse.
Exemples
Remarque : Les langages de programmation compatibles ne figurent pas tous dans les exemples de code présentés pour cette méthode (consultez la page Bibliothèques clientes pour obtenir la liste des langages compatibles).
Java
Utilise la bibliothèque cliente 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
Utilise la bibliothèque cliente .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
Utilise la bibliothèque cliente 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
Utilise la bibliothèque 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
Ruby
Utilise la bibliothèque cliente 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
Utilise la bibliothèque cliente 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 brut
N'utilise pas de bibliothèque 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"] }