Subscriptions: update

승인 필요

기존 구독을 업데이트합니다. 예를 참조하세요.

요청

HTTP 요청

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

매개변수

매개변수 이름 설명
경로 매개변수
id string 정기 결제의 ID입니다.

확인할 내용

이 요청을 처리하려면 다음 범위의 승인을 받아야 합니다 (인증 및 승인 자세히 알아보기).

범위
https://www.googleapis.com/auth/glass.timeline

요청 본문

요청 본문에서는 다음과 같은 속성을 사용하여 정기 결제 리소스를 제공합니다.

숙소 이름 설명 메모
필수 속성
callbackUrl string 알림을 전송해야 하는 URL입니다 (https://로 시작해야 함). 쓰기 가능
collection string 구독할 컬렉션입니다. 허용되는 값은 다음과 같습니다.
  • timeline - 삽입, 삭제, 업데이트 등 타임라인의 변경사항입니다.
  • locations - 위치 업데이트
  • settings - 설정 업데이트
쓰기 가능
선택 속성
operation[] list 구독해야 하는 작업 목록입니다. 빈 목록은 컬렉션의 모든 작업을 구독해야 함을 나타냅니다. 허용되는 값은 다음과 같습니다.
  • UPDATE - 항목이 업데이트되었습니다.
  • INSERT - 새 항목이 삽입되었습니다.
  • DELETE - 항목이 삭제되었습니다.
쓰기 가능
userToken string 사용자의 ID를 파악할 수 있도록 알림에서 구독자에게 전달되는 불투명한 토큰입니다. 쓰기 가능
verifyToken string Google에서 알림을 생성했음을 확인할 수 있도록 알림에서 구독자에게 전송되는 비밀번호 토큰입니다. 쓰기 가능

응답

요청에 성공할 경우 이 메서드는 응답 본문에 Subscriptions 리소스를 반환합니다.

참고: 이 메서드에 제공되는 코드 예시가 지원되는 모든 프로그래밍 언어를 나타내는 것은 아닙니다. 지원되는 언어 목록은 클라이언트 라이브러리 페이지를 참조하세요.

자바

자바 클라이언트 라이브러리를 사용합니다.

import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Subscription;

import java.io.IOException;
import java.util.List;

public class MyClass {
  // ...

  /**
   * Update an existing subscription for the current user.
   * 
   * @param service Authorized Mirror service.
   * @param collection Collection to subscribe to (supported values are "timeline" and 
   *        "locations").
   * @param newUserToken Opaque token used by the Glassware to identify the user
   *        the notification pings are sent for (recommended).
   * @param newVerifyToken Opaque token used by the Glassware to verify that the
   *        notification pings are sent by the API (optional).
   * @param newCallbackUrl URL receiving notification pings (must be HTTPS).
   * @param newOperation List of operations to subscribe to. Valid values are
   *        "UPDATE", "INSERT" and "DELETE" or {@code null} to subscribe to all.
   */
  public static void updateSubscription(Mirror service, String collection, String newUserToken,
      String newVerifyToken, String newCallbackUrl, List<String> newOperation) {
    Subscription subscription = new Subscription();
    subscription.setCollection(collection).setUserToken(newUserToken)
        .setVerifyToken(newVerifyToken).setCallbackUrl(newCallbackUrl).setOperation(newOperation);
    try {
      service.subscriptions().update(collection, subscription).execute();
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
    }
  }
  
  // ...
}

.NET

.NET 클라이언트 라이브러리를 사용합니다.

using System;
using System.Collections.Generic;

using Google.Apis.Mirror.v1;
using Google.Apis.Mirror.v1.Data;

public class MyClass {
  // ...

  /// <summary>
  /// Update an existing subscription for the current user.
  /// </summary>
  /// <param name='service'>Authorized Mirror service.</param>
  /// <param name='collection'>
  /// Collection to subscribe to (supported values are "timeline" and
  /// "locations").
  /// </param>
  /// <param name='newUserToken'>
  /// Opaque token used by the Glassware to identify the user the
  /// notification pings are sent for (recommended).
  /// </param>
  /// <param name='newVerifyToken'>
  /// Opaque token used by the Glassware to verify that the notification
  /// pings are sent by the API (optional).
  /// </param>
  /// <param name='newCallbackUrl'>
  /// URL receiving notification pings (must be HTTPS).
  /// </param>
  /// <param name='newOperation'>
  /// List of operations to subscribe to. Valid values are "UPDATE", "INSERT"
  /// and "DELETE" or {@code null} to subscribe to all.
  /// </param>
  public static void updateSubscription(MirrorService service,
      String collection, String newUserToken, String newVerifyToken,
      String newCallbackUrl, List<String> newOperation) {
    Subscription subscription = new Subscription() {
      Collection = collection,
      UserToken = newUserToken,
      VerifyToken = newVerifyToken,
      CallbackUrl = newCallbackUrl,
      Operation = newOperation
    };
    try {
      service.Subscriptions.Update(subscription, collection).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...
}

PHP

PHP 클라이언트 라이브러리를 사용합니다.

/**
 * Update an existing subscription for the current user.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $collection Collection to subscribe to (supported
 *                           values are "timeline" and "locations").
 * @param string $newUserToken Opaque token used by the Service to
 *                             identify the  user the notification pings
 *                             are sent for (recommended).
 * @param string $newVerifyToken Opaque token used by the Service to verify
 *                              that the notification pings are sent by
 *                              the API (optional).
 * @param string $newCallbackUrl URL receiving notification pings
 *                               (must be HTTPS).
 * @param Array $newOperation List of operations to subscribe to. Valid values
 *                            are "UPDATE", "INSERT" and "DELETE" or
 *                            null to subscribe to all.
 */
function subscribeToNotifications($service, $collection, $newUserToken,
    $newVerifyToken, $newCallbackUrl, $newOperation) {
  try {
    $subscription = new Google_Subscription();
    $subscription->setCollection($collection);
    $subscription->setUserToken($newUserToken);
    $subscription->setVerifyToken($newVerifyToken);
    $subscription->setCallbackUrl($newCallbackUrl);
    $subscription->setOperation($onewOeration);
    $service->subscriptions->update($collection, $subscription);
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
  }
}

Python

Python 클라이언트 라이브러리를 사용합니다.

from apiclient import errors
# ...

def update_subscription(service, collection, new_user_token, new_verify_token,
                        new_callback_url, new_operation):
  """Update an existing subscription for the current user.

  Args:
    service: Authorized Mirror service.
    collection: Collection to subscribe to (supported values are "timeline" and
                "locations").
    new_user_token: Opaque token used by the Glassware to identify the user the
                    notification pings are sent for (recommended).
    new_verify_token: Opaque token used by the Glassware to verify that the
                      notification pings are sent by the API (optional).
    new_callback_url: URL receiving notification pings (must be HTTPS).
    new_operation: List of operations to subscribe to. Valid values are
                   "UPDATE", "INSERT" and "DELETE" or None to subscribe to all.
  """
  subscription = {
      'collection': collection,
      'userToken': new_user_token,
      'verifyToken': new_verify_token,
      'callbackUrl': new_callback_url,
      'operation': new_operation
   }
  try:
    service.subscriptions().update(id=collection, body=subscription).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % e

Ruby

Ruby 클라이언트 라이브러리를 사용합니다.

##
# Update an existing subscription for the current user.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] collection
#   Collection to subscribe to (supported values are "timeline" and "locations").
# @param [String] new_user_token
#   Opaque token used by the Glassware to identify the user the notification
#   pings are sent for (recommended).
# @param [String] verify_token
#   Opaque token used by the Glassware to verify that the notification pings are
#   sent by the API (optional).
# @param [String] new_callback_url
#   URL receiving notification pings (must be HTTPS).
# @param [Array] new_operation
#   List of operations to subscribe to. Valid values are "UPDATE", "INSERT" and
#   "DELETE" or nil to subscribe to all.
# @return nil
def update_subscription(client, collection, new_user_token, new_verify_token,
                        new_callback_url, new_operation)
  mirror = client.discovered_api('mirror', 'v1')
  subscription = mirror.subscriptions.update.request_schema.new({
    'collection' => collection,
    'userToken' => new_user_token,
    'verifyToken' => new_verify_token,
    'callbackUrl' => new_callback_url,
    'operation' => new_operation})
  result = client.execute(
    :api_method => mirror.subscriptions.update,
    :body_object => subscription,
    :parameters => { 'id' => collection })
  if result.error?
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

Go

Go 클라이언트 라이브러리 사용

import (
	"code.google.com/p/google-api-go-client/mirror/v1"
	"fmt"
)

// UpdateSubscription updates an existing subscription for the current user
func UpdateSubscription(g *mirror.Service, collection string,
	newUserToken string, newVerifyToken string, newCallbackUrl string,
	operations []string) (*mirror.Subscription, error) {
	s := &mirror.Subscription{
		Collection:  collection,
		UserToken:   newUserToken,
		VerifyToken: newVerifyToken,
		CallbackUrl: newCallbackUrl,
	}
	r, err := g.Subscriptions.Update(collection, s).Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	return r, nil
}

원시 HTTP

클라이언트 라이브러리를 사용하지 않습니다.

PUT /mirror/v1/subscriptions/timeline HTTP/1.1
Authorization: Bearer auth token
Content-Type: application/json
Content-Length: length

{
  "collection": "timeline"
  "userToken": "harold_penguin",
  "callbackUrl": "https://example.com/notify/callback"
}