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 – משתפת פריט בציר הזמן עם תמליל של דיבור מהמשתמש, מהפקודה הקולית "Take a note" לתפריט.
  • POST_AN_UPDATE – משתף פריט בציר הזמן עם תמליל של דיבור מהמשתמש מהפקודה "פרסום עדכון" בתפריט הקולי.
ניתן לכתיבה
displayName string השם שיוצג לאיש הקשר הזה. ניתן לכתיבה
id string המזהה של איש הקשר הזה. האפליקציה הזו יוצרת אסימון אטום. ניתן לכתיבה
imageUrls[] list קבוצה של כתובות URL של תמונות להצגה עבור איש קשר. לרוב אנשי הקשר תהיה תמונה אחת, אבל איש קשר מסוג "קבוצה" עשוי לכלול עד 8 כתובות URL של תמונות, והגודל שלהן ייחתך ויחתך לתוך הפסיפס אצל הלקוח. ניתן לכתיבה
מאפיינים אופציונליים
acceptCommands[] list רשימת פקודות בתפריט קולי שאיש קשר יכול לטפל בהן. Glass מציג עד שלושה אנשי קשר לכל פקודת תפריט קולי. אם יש יותר מערך זה, יוצגו שלושת אנשי הקשר עם הערך הגבוה ביותר של priority עבור אותה פקודה. ניתן לכתיבה
acceptTypes[] list רשימה של סוגי MIME שנתמכים על ידי איש קשר. איש הקשר יוצג למשתמש אם אחד מסוגי ה-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

משתמש בספריית הלקוחות של Rubby.

##
# 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

נעשה שימוש בספריית הלקוחות של 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"]
}