Contacts: update

تتطلّب تفويضًا

تعديل جهة اتصال حالية اطّلِع على مثال.

الطلب

طلب HTTP

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

المعلمات

اسم المعلَمة القيمة الوصف
مَعلمات المسار
id string رقم تعريف جهة الاتصال.

التفويض

يتطلب هذا الطلب تفويضًا بالنطاق التالي (مزيد من المعلومات عن المصادقة والترخيص).

النطاق
https://www.googleapis.com/auth/glass.timeline

نص الطلب

في نص الطلب، قدِّم مرجع جهات اتصال يتضمّن السمات التالية:

اسم الموقع القيمة الوصف ملاحظات
الخصائص المطلوبة
acceptCommands[].type string نوع العملية التي يتوافق معها هذا الأمر. القيم المسموح بها هي:
  • TAKE_A_NOTE - يشارك عنصر مخطط زمني مع تحويل صوت الكلام إلى نص من قسم "تدوين ملاحظة". طلب القائمة الصوتية.
  • POST_AN_UPDATE - مشاركة عنصر مخطط زمني مع نص نطق المستخدم من أمر القائمة الصوتية "نشر إشعار"
قابل للكتابة
displayName string الاسم الذي سيتم عرضه لجهة الاتصال هذه. قابلة للكتابة
id string رقم تعريف لجهة الاتصال هذه. يتم إنشاء هذا بواسطة التطبيق ويتم التعامل معه كرمز مميز مبهم. قابل للكتابة
imageUrls[] list مجموعة عناوين URL للصور التي سيتم عرضها لجهة اتصال. ستتضمّن معظم جهات الاتصال صورة واحدة، ولكن قد تتضمّن جهة اتصال "المجموعة" ما يصل إلى 8 عناوين URL للصور، وسيتم تغيير حجمها واقتصاصها لإنشاء لوحة فسيفساء على العميل. قابل للكتابة
السمات الاختيارية
acceptCommands[] list قائمة بأوامر القائمة الصوتية التي يمكن لجهة اتصال التعامل معها. يعرض Glass ما يصل إلى ثلاث جهات اتصال لكل طلب من طلبات القائمة الصوتية. إذا كان هناك أكثر من ذلك، يتم عرض جهات الاتصال الثلاث التي تملك أعلى قيمة priority لهذا الطلب المحدّد. قابل للكتابة
acceptTypes[] list قائمة بأنواع MIME التي تتيحها جهة الاتصال سيتم عرض جهة الاتصال للمستخدم إذا كان أي من علامات AcceptTypes يتطابق مع أي من أنواع المرفقات على العنصر. في حال عدم تقديم AcceptTypes، سيتم عرض جهة الاتصال لجميع العناصر. قابل للكتابة
phoneNumber string رقم الهاتف الأساسي لجهة الاتصال. يمكن أن يكون هذا رقمًا مؤهَّلاً بالكامل، مع رمز الاتصال بالبلد ورمز المنطقة، أو رقمًا محليًا. قابلة للكتابة
priority unsigned integer الأولوية لجهة الاتصال لتحديد الترتيب في قائمة جهات الاتصال سيتم عرض جهات الاتصال ذات الأولوية الأعلى قبل جهات الاتصال ذات الأولوية الأقل. قابلة للكتابة
speakableName string اسم جهة الاتصال كما يجب لفظه إذا كان يجب قول اسم جهة الاتصال هذه كجزء من قائمة تحديد الهوية الصوتي، يتم استخدام هذا الاسم كطريقة اللفظ المتوقّعة. يكون هذا مفيدًا لأسماء جهات الاتصال التي تحتوي على أحرف لا يمكن لفظها أو التي لا تكون تهجئتها الصوتية هي نفسها التهجئة المعروضة. قابل للكتابة
type string نوع جهة الاتصال هذه. يتم استخدام هذا الإجراء للترتيب في واجهات المستخدم. القيم المسموح بها هي:
  • INDIVIDUAL: يمثّل شخصًا واحدًا. هذا هو الخيار التلقائي.
  • GROUP - يمثل أكثر من شخص واحد.
قابلة للكتابة

الرد

في حال نجاح هذه الطريقة، ستُرجع مرجع جهات الاتصال في نص الاستجابة.

أمثلة

ملاحظة: إنّ الأمثلة المرتبطة بالرموز والمتوفرة لهذه الطريقة لا تمثّل كل لغات البرمجة المتوافقة (يُرجى مراجعة صفحة مكتبات البرامج للاطّلاع على قائمة باللغات المتوافقة).

Java

يستخدم مكتبة برامج 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.

لاستخدام مكتبة برامج .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

لاستخدام مكتبة برامج 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

يستخدم مكتبة برامج 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

تستخدم مكتبة برامج 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"]
}