Richiede l'autorizzazione
Aggiorna un contatto. Vedi un esempio.
Risorse richieste:
Richiesta HTTP
PUT https://www.googleapis.com/mirror/v1/contacts/id
Parametri
Nome del parametro | Valore | Descrizione |
---|---|---|
Parametri percorso | ||
id |
string |
L'ID del contatto. |
Autorizzazione
Questa richiesta richiede l'autorizzazione con il seguente ambito (scopri di più su autenticazione e autorizzazione).
Ambito |
---|
https://www.googleapis.com/auth/glass.timeline |
Corpo della richiesta
Nel corpo della richiesta, fornisci una risorsa Contatti con le seguenti proprietà:
Nome proprietà | Valore | Descrizione | Note |
---|---|---|---|
Proprietà obbligatorie | |||
acceptCommands[].type |
string |
Il tipo di operazione a cui corrisponde questo comando. I valori consentiti sono:
|
scrivibile |
displayName |
string |
Il nome da visualizzare per questo contatto. | scrivibile |
id |
string |
L'ID di questo contatto. Viene generato dall'applicazione e considerato come un token opaco. | scrivibile |
imageUrls[] |
list |
Insieme di URL di immagini da mostrare per un contatto. La maggior parte dei contatti avrà una singola immagine, ma un contatto "gruppo" può includere fino a 8 URL immagine e verranno ridimensionati e ritagliati in un mosaico sul client. | scrivibile |
Proprietà facoltative | |||
acceptCommands[] |
list |
Un elenco di comandi vocali che un contatto può gestire. Glass mostra fino a tre contatti per ciascun comando di menu vocale. Se superiore, vengono visualizzati i tre contatti con il numero di richieste (priority ) più alto per quel particolare comando. |
scrivibile |
acceptTypes[] |
list |
Un elenco dei tipi MIME supportati da un contatto. Il contatto verrà mostrato all'utente se uno dei relativi accettaType corrisponde a uno dei tipi di allegati dell'elemento. Se non specifichi un valore accettaType, il contatto verrà visualizzato per tutti gli elementi. | scrivibile |
phoneNumber |
string |
Numero di telefono principale del contatto. Può trattarsi di un numero completo, con prefisso internazionale e un prefisso. | scrivibile |
priority |
unsigned integer |
Priorità del contatto per determinare l'ordine in un elenco di contatti. I contatti con priorità più alte verranno mostrati prima di quelli con priorità più bassa. | scrivibile |
speakableName |
string |
Nome del contatto, come deve essere pronunciato. Se è necessario pronunciare il nome di questo contatto come parte di un menu di disambiguazione vocale, questo nome verrà utilizzato come pronuncia prevista. È utile per i nomi dei contatti con caratteri imprevedibili o la cui ortografia display non è fonetica. | scrivibile |
type |
string |
Il tipo di questo contatto. Utilizzato per ordinare le UI. I valori consentiti sono:
|
scrivibile |
Risposta
In caso di esito positivo, questo metodo restituisce una risorsa Contatti nel corpo della risposta.
Esempi
Nota: gli esempi di codice disponibili per questo metodo non rappresentano tutti i linguaggi di programmazione supportati (consulta la pagina relativa alle librerie client per un elenco dei linguaggi supportati).
Java
Utilizza la libreria client di 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
Utilizza la libreria client di .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
Utilizza la libreria client di 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
Utilizza la libreria client di 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
Utilizza la libreria client di 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
Utilizza la libreria client di 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 non elaborato
Non utilizza una libreria client.
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"] }