Subscriptions: list

Yetkilendirme gerektiriyor

Kimliği doğrulanmış kullanıcı ve hizmet için abonelik listesini alır. Örneğe göz atın.

İstek

HTTP isteği

GET https://www.googleapis.com/mirror/v1/subscriptions

Yetkilendirme

Bu istek, aşağıdaki kapsamla yetkilendirme gerektiriyor (kimlik doğrulama ve yetkilendirme hakkında daha fazla bilgi edinin).

Kapsam
https://www.googleapis.com/auth/glass.timeline

İstek içeriği

Bu yöntemle istek gövdesi sağlamayın.

Yanıt

Başarılı olursa bu yöntem, aşağıdaki yapıya sahip bir yanıt gövdesi döndürür:

{
  "kind": "mirror#subscriptionsList",
  "items": [
    subscriptions Resource
  ]
}
Mülk adı Değer Açıklama Notlar
kind string Kaynağın türü. Bu her zaman mirror#subscriptionsList.
items[] list Abonelik listesi.

Örnekler

Not: Bu yöntem için kullanıma sunulan kod örnekleri, desteklenen tüm programlama dillerini kapsamaz (Desteklenen dillerin listesi için istemci kitaplıkları sayfasını inceleyin).

Java

Java istemci kitaplığını kullanır.

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

import java.io.IOException;

public class MyClass {
  // ...

  /**
   * Print the notification subscriptions for the current user.
   * 
   * @param service Authorized Mirror service.
   */
  public static void printSubscriptions(Mirror service) {
    try {
      SubscriptionsListResponse subscriptions = service.subscriptions().list().execute();

      for (Subscription subscription : subscriptions.getItems()) {
        System.out.println("Collection: " + subscription.getCollection());
        System.out.println("User token: " + subscription.getUserToken());
        System.out.println("Verify token: " + subscription.getVerifyToken());
        System.out.println("Callback URL: " + subscription.getCallbackUrl());

        if (subscription.getOperation() != null && subscription.getOperation().size() > 0) {
          System.out.println("Operation:");
          for (String operation : subscription.getOperation()) {
            System.out.println("  * " + operation);
          }
        } else {
          System.out.println("Operation: ALL");
        }
      }
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
    }
  }
  
  // ...
}

.NET

.NET istemci kitaplığını kullanır.

using System;

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

public class MyClass {
  // ...

  /// <summary>
  /// Print the notification subscriptions for the current user.
  /// </summary>
  /// <param name='service'>Authorized Mirror service.</param>
  public static void PrintSubscriptions(MirrorService service) {
    try {
      SubscriptionsListResponse subscriptions =
          service.Subscriptions.List().Fetch();

      foreach (Subscription subscription in subscriptions.Items) {
        Console.WriteLine("Collection: " + subscription.Collection);
        Console.WriteLine("User token: " + subscription.UserToken);
        Console.WriteLine("Verify token: " + subscription.VerifyToken);
        Console.WriteLine("Callback URL: " + subscription.CallbackUrl);

        if (subscription.Operation != null &&
          subscription.Operation.Count > 0) {
          Console.WriteLine("Operation:");
          foreach (String operation in subscription.Operation) {
            Console.WriteLine("  * " + operation);
          }
        } else {
          Console.WriteLine("Operation: ALL");
        }
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...
}

PHP

PHP istemci kitaplığını kullanır.

/**
 * Print the notification subscriptions for the current user.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 */
function printSubscriptions($service) {
  try {
    $subscriptions = $service->subscriptions->listSubscriptions();

    foreach ($subscriptions->getItems() as $subscription) {
      print 'Collection: ' . $subscription->getCollection();
      print 'User token: ' . $subscription->getUserToken();
      print 'Verify token: ' . $subscription->getVerifyToken();
      print 'Callback URL: ' . $subscription->getCallbackUrl();

      if ($subscription->getOperation()) {
        print 'Operation:';
        foreach ($subscription->getOperation() as $operation) {
          print '  * ' . $operation;
        }
        print 'Operation: ALL';
      }
    }
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
  }
}

Python

Python istemci kitaplığını kullanır.

from apiclient import errors
# ...

def print_subscriptions(service):
  """Print the notification subscriptions for the current user.

  Args:
    service: Authorized Mirror service.
  """
  try:
    subscriptions = service.subscriptions().list().execute()

    for subscription in subscriptions.get('items', []):
      print 'Collection: %s' % subscription.get('collection')
      print 'User token: %s' % subscription.get('userToken')
      print 'Verify token: %s' % subscription.get('verifyToken')
      print 'Callback URL: %s' % subscription.get('callbackUrl')

      if subscription.get('operation'):
        print 'Operation:'
        for operation in subscription['operation']:
          print '  * %s' % operation
      else:
        print 'Operation: ALL'
  except errors.HttpError, e:
    print 'An error occurred: %s' % e

Ruby

Ruby istemci kitaplığını kullanır.

##
# Print the notification subscriptions for the current user.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @return nil
def print_subscriptions(client)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(:api_method => mirror.subscriptions.list)
  if result.success?
    subscriptions = result.data
    subscriptions.items.each do |subscription|
      puts "Collection: #{subscription.collection}"
      puts "User token: #{subscription.user_token}"
      puts "Verify token: #{subscription.verify_token}"
      puts "Callback URL: #{subscription.callback_url}"

      if !subscription.operation.empty?
        puts "Operation:"
        subscription.operation.each do |operation|
          puts "  * #{operation}"
        end
      else
        puts "Operation: ALL"
      end
    end
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

Go

Go istemci kitaplığını kullanır.

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

// PrintSubscriptions prints the notification subscriptions for the current
// user.
func PrintSubscriptions(g *mirror.Service) error {
	sl, err := g.Subscriptions.List().Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return err
	}
	for _, s := range sl.Items {
		fmt.Printf("Collection: %s\n", s.Collection)
		fmt.Printf("User token: %s\n", s.UserToken)
		fmt.Printf("Verify token: %s\n", s.VerifyToken)
		fmt.Printf("Callback URL: %s\n", s.CallbackUrl)

		if len(s.Operation) > 0 {
			fmt.Printf("Operation:")
			for _, o := range s.Operation {
				fmt.Printf("  * %s\n", o)
			}
		} else {
			fmt.Printf("Operation: ALL")
		}
	}
	return nil
}

Ham HTTP

İstemci kitaplığı kullanmaz.

GET /mirror/v1/subscriptions HTTP/1.1
Authorization: Bearer auth token