Contacts: patch

इसके लिए, अनुमति देना ज़रूरी है

किसी संपर्क को अपडेट करता है. यह तरीका पैच सिमेंटिक के साथ काम करता है. उदाहरण देखें.

अनुरोध करें

एचटीटीपी अनुरोध

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

पैरामीटर

पैरामीटर का नाम वैल्यू ब्यौरा
पाथ पैरामीटर
id string संपर्क का आईडी.

अनुमति देना

इस अनुरोध को नीचे दिए गए दायरे के साथ अनुमति देना ज़रूरी है (पुष्टि करने और मंज़ूरी देने के बारे में ज़्यादा पढ़ें).

स्कोप
https://www.googleapis.com/auth/glass.timeline

अनुरोध का मुख्य भाग

अनुरोध के मुख्य भाग में, पैच सिमैंटिक के नियमों के मुताबिक, संपर्क संसाधन के काम के हिस्से डालें.

जवाब

अगर यह सफल होता है, तो यह तरीका रिस्पॉन्स के मुख्य भाग में संपर्क संसाधन दिखाता है.

उदाहरण

ध्यान दें: इस तरीके के लिए दिए गए कोड के उदाहरणों में इसके साथ काम करने वाली सभी प्रोग्रामिंग भाषाएं नहीं दिखाई गई हैं (इसके साथ काम करने वाली भाषाओं की सूची के लिए क्लाइंट लाइब्रेरी वाला पेज देखें).

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) {
    Contact patchedContact = new Contact();
    patchedContact.setDisplayName(newDisplayName);

    try {
      return service.contacts().patch(contactId, patchedContact).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>
  /// Patched contact on success, null otherwise.
  /// </returns>
  public static Contact RenameContact(MirrorService service,
      String contactId, String newDisplayName) {
    Contact patchedContact = new Contact() {
      DisplayName = newDisplayName
    };
    try {
      return service.Contacts.Patch(
          patchedContact, 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 Patched contact on success, null otherwise.
 */
function renameContact($service, $contactId, $newDisplayName) {
  try {
    $patchedContact = new Google_Contact();
    $patchedContact->setDisplayName($newDisplayName);
    return $service->contacts->patch($contactId, $patchedContact);
  } 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.
  """
  patched_contact = {'displayName': new_display_name}
  try:
    return service.contacts().patch(
        id=contact_id, body=patched_contact).execute()
  except errors.HttpError, error:
    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]
#   Patched contact on success, nil otherwise.
def rename_contact(client, contact_id, new_display_name)
  mirror = client.discovered_api('mirror', 'v1')
  patched_contact = mirror.contacts.patch.request_schema.new({
    'displayName' => new_display_name
  })
  result = client.execute(
    :api_method => mirror.contacts.patch,
    :parameters => { 'id' => contact_id },
    :body_object => contact)
  if result.success?
    return result.data
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
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 := &mirror.Contact{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
}

रॉ एचटीटीपी

क्लाइंट लाइब्रेरी का इस्तेमाल नहीं करता.

PATCH /mirror/v1/contacts/harold HTTP/1.1
Authorization: Bearer auth token
Content-Type: application/json
Content-Length: length

{
  "displayName": "Harold Penguin"
}