Contacts: update

Memerlukan otorisasi

Memperbarui kontak diterapkan. Lihat contoh.

Permintaan

Permintaan HTTP

PUT https://www.googleapis.com/mirror/v1/contacts/id

Parameter

Nama parameter Nilai Deskripsi
Parameter jalur
id string ID kontak.

Otorisasi

Permintaan ini memerlukan otorisasi dengan cakupan berikut (baca lebih lanjut tentang autentikasi dan otorisasi).

Cakupan
https://www.googleapis.com/auth/glass.timeline

Isi permintaan

Dalam isi permintaan, sediakan resource Kontak dengan properti berikut:

Nama properti Nilai Deskripsi Catatan
Properti yang Diperlukan
acceptCommands[].type string Jenis operasi yang sesuai dengan perintah ini. Nilai yang diizinkan adalah:
  • TAKE_A_NOTE - Membagikan item linimasa dengan transkripsi ucapan pengguna dari perintah menu suara "Buat catatan".
  • POST_AN_UPDATE - Membagikan item linimasa dengan transkripsi ucapan pengguna dari perintah menu suara "Posting update".
dapat ditulis
displayName string Nama yang akan ditampilkan untuk kontak ini. dapat ditulis
id string ID untuk kontak ini. Ini dibuat oleh aplikasi dan diperlakukan sebagai token buram. dapat ditulis
imageUrls[] list Kumpulan URL gambar yang akan ditampilkan untuk kontak. Sebagian besar kontak akan memiliki satu gambar, tetapi satu kontak "grup" dapat menyertakan hingga 8 URL gambar dan kontak tersebut akan diubah ukurannya dan dipangkas menjadi mozaik pada klien. dapat ditulis
Properti Opsional
acceptCommands[] list Daftar perintah menu suara yang dapat ditangani kontak. Glass menampilkan hingga tiga kontak untuk setiap perintah menu suara. Jika ada lebih dari itu, tiga kontak dengan priority tertinggi akan ditampilkan untuk perintah khusus tersebut. dapat ditulis
acceptTypes[] list Daftar jenis MIME yang didukung oleh kontak. Kontak akan ditampilkan kepada pengguna jika salah satu AcceptTypes-nya cocok dengan salah satu jenis lampiran pada item. Jika tidak ada allowTypes yang diberikan, kontak akan ditampilkan untuk semua item. dapat ditulis
phoneNumber string Nomor telepon utama untuk kontak. Ini dapat berupa nomor yang sepenuhnya memenuhi syarat, dengan kode panggilan negara dan kode area, atau nomor lokal. dapat ditulis
priority unsigned integer Prioritas kontak untuk menentukan urutan dalam daftar kontak. Kontak dengan prioritas lebih tinggi akan ditampilkan sebelum kontak dengan prioritas lebih rendah. dapat ditulis
speakableName string Nama kontak ini karena harus diucapkan. Jika nama kontak ini harus diucapkan sebagai bagian dari menu disambiguasi suara, nama ini digunakan sebagai pengucapan yang diharapkan. Hal ini berguna untuk nama kontak dengan karakter yang tidak dapat diucapkan atau ejaan tampilan yang tidak bersifat fonetik. dapat ditulis
type string Jenis kontak ini. Ini digunakan untuk mengurutkan di UI. Nilai yang diizinkan adalah:
  • INDIVIDUAL - Mewakili satu orang. Ini adalah defaultnya.
  • GROUP - Mewakili lebih dari satu orang.
dapat ditulis

Tanggapan

Jika berhasil, metode ini menampilkan Resource kontak di isi respons.

Contoh

Catatan: Contoh kode yang tersedia untuk metode ini tidak merepresentasikan semua bahasa pemrograman yang didukung (lihat halaman library klien untuk mengetahui daftar bahasa yang didukung).

Java

Menggunakan library klien 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

Menggunakan library klien.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

Menggunakan library klien 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

Menggunakan library klien 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

Menggunakan library klien 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

Menggunakan library klien 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 Mentah

Tidak menggunakan library klien.

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"]
}