Contacts: update

نیاز به مجوز دارد

یک مخاطب را در جای خود به روز می کند. یک نمونه ببینید .

درخواست

درخواست HTTP

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

مولفه های

نام پارامتر ارزش شرح
پارامترهای مسیر
id string شناسه مخاطب

مجوز

این درخواست به مجوز با محدوده زیر نیاز دارد ( در مورد احراز هویت و مجوز بیشتر بخوانید ).

محدوده
https://www.googleapis.com/auth/glass.timeline

درخواست بدن

در بدنه درخواست، یک منبع Contacts با ویژگی های زیر ارائه کنید:

نام ملک ارزش شرح یادداشت
خواص مورد نیاز
acceptCommands[]. type string نوع عملیات مربوط به این دستور. مقادیر مجاز عبارتند از:
  • TAKE_A_NOTE - یک مورد جدول زمانی را با رونویسی گفتار کاربر از فرمان منوی صوتی "یادداشت بردارید" به اشتراک می گذارد.
  • POST_AN_UPDATE - یک مورد خط زمانی را با رونویسی گفتار کاربر از فرمان منوی صوتی "پست یک به روز رسانی" به اشتراک می گذارد.
قابل نوشتن
displayName string نامی که برای این مخاطب نمایش داده می شود. قابل نوشتن
id string شناسه ای برای این مخاطب این توسط برنامه ایجاد می شود و به عنوان یک نشانه غیر شفاف در نظر گرفته می شود. قابل نوشتن
imageUrls[] list مجموعه ای از URL های تصویر برای نمایش برای یک مخاطب. بیشتر مخاطبین یک تصویر واحد خواهند داشت، اما یک مخاطب "گروهی" ممکن است تا 8 URL تصویر را شامل شود و اندازه آنها تغییر کرده و به صورت موزاییکی روی مشتری برش داده می شود. قابل نوشتن
ویژگی های اختیاری
acceptCommands[] list فهرستی از دستورات منوی صوتی که مخاطب می تواند از عهده آنها برآید. شیشه حداکثر سه مخاطب را برای هر فرمان منوی صوتی نشان می دهد. اگر بیشتر از آن وجود داشته باشد، سه مخاطب با بالاترین priority برای آن دستور خاص نشان داده می شوند. قابل نوشتن
acceptTypes[] list لیستی از انواع MIME که یک مخاطب از آنها پشتیبانی می کند. اگر هر یک از نوع های پذیرش آن با هر یک از انواع پیوست های موجود در مورد مطابقت داشته باشد، مخاطب به کاربر نشان داده می شود. اگر هیچ نوع AcceptType داده نشود، مخاطب برای همه موارد نشان داده می شود. قابل نوشتن
phoneNumber string شماره تلفن اصلی برای مخاطب این می تواند یک شماره کاملاً واجد شرایط، با کد تماس کشور و کد منطقه، یا یک شماره محلی باشد. قابل نوشتن
priority unsigned integer اولویت برای مخاطب برای تعیین ترتیب در لیستی از مخاطبین. مخاطبین با اولویت بالاتر قبل از مخاطبین با اولویت کمتر نشان داده می شوند. قابل نوشتن
speakableName string نام این مخاطب همانطور که باید تلفظ شود. اگر نام این مخاطب باید به عنوان بخشی از منوی ابهام‌زدایی صدا گفته شود، از این نام به عنوان تلفظ مورد انتظار استفاده می‌شود. این برای نام‌های مخاطب با نویسه‌های غیرقابل تلفظ مفید است یا املای نمایش آن‌ها در غیر این صورت آوایی نیست. قابل نوشتن
type string نوع این مخاطب این برای مرتب سازی در UI ها استفاده می شود. مقادیر مجاز عبارتند از:
  • INDIVIDUAL - نماینده یک فرد مجرد است. این پیش فرض است.
  • GROUP - بیش از یک نفر را نشان می دهد.
قابل نوشتن

واکنش

در صورت موفقیت آمیز بودن، این روش یک منبع Contacts را در بدنه پاسخ باز می گرداند.

مثال ها

توجه: نمونه‌های کد موجود برای این روش همه زبان‌های برنامه‌نویسی پشتیبانی‌شده را نشان نمی‌دهند (برای فهرست زبان‌های پشتیبانی‌شده به صفحه کتابخانه‌های سرویس گیرنده مراجعه کنید).

جاوا

از کتابخانه سرویس گیرنده جاوا استفاده می کند.

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;
    }
  }

  // ...
}

.خالص

از کتابخانه کلاینت دات نت استفاده می کند.

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

از کتابخانه مشتری 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;
  }
}

پایتون

از کتابخانه کلاینت پایتون استفاده می کند.

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 استفاده می کند.

##
# 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 استفاده می کند.

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 خام

از کتابخانه مشتری استفاده نمی کند.

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