Subscriptions: delete

需要授權

刪除訂閱項目。 參閲範例

要求

HTTP 要求

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

參數

參數名稱 說明
路徑參數
id string 訂閱項目的 ID。

授權

此要求需要以下範圍的授權 (進一步瞭解驗證和授權)。

範圍
https://www.googleapis.com/auth/glass.timeline

要求主體

請不要透過此方法提供請求主體。

回應

如果成功,此方法會傳回空白的回應主體。

範例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 Java 用戶端程式庫

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

import java.io.IOException;

public class MyClass {
  // ...

  /**
   * Delete a subscription to a collection.
   * 
   * @param service Authorized Mirror service.
   * @param collection Collection to unsubscribe from (supported values are
   *        "timeline" and "locations").
   */
  public static void unsubscribeFromNotifications(Mirror service, String collection) {
    try {
      service.subscriptions().delete(collection).execute();
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
    }
  }

  // ...
}

.NET

使用 .NET 用戶端程式庫

using System;

using Google.Apis.Mirror.v1;

public class MyClass {
  // ...

  /// <summary>
  /// Delete a subscription to a collection.
  /// </summary>
  /// <param name='service'>Authorized Mirror service.</param>
  /// <param name='collection'>
  /// Collection to unsubscribe from (supported values are "timeline" and
  /// "locations").
  /// </param>
  public static void UnsubscribeFromNotifications(MirrorService service,
      String collection) {
    try {
      service.Subscriptions.Delete(collection).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...
}

PHP

使用 PHP 用戶端程式庫

/**
 * Delete a subscription to a collection.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $collection Collection to unsubscribe from (supported values
 *                           are "timeline" and "locations").
 */
function unsubscribeFromNotifications($service, $collection) {
  try {
    $service->subscriptions->delete($collection);
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
  }
}

Python

使用 Python 用戶端程式庫

from apiclient import errors
# ...

def unsubscribe_from_notifications(service, collection):
  """Delete a subscription to a collection.

  Args:
    service: Authorized Mirror service.
    collection: Collection to unsubscribe from (supported values are
                "timeline" and "locations"
  """
  try:
    service.subscriptions().delete(collection).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

使用 Ruby 用戶端程式庫

##
# Delete a subscription to a collection.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] collection
#   Collection to unsubscribe from (supported values are "timeline" and
#   "locations").
# @return nil
def unsubscribe_from_notifications(client, collection)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(
    :api_method => mirror.subscriptions.delete,
    :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"
)

// UnsubscribeFromNotifications deletes a subscription to a collection.
func UnsubscribeFromNotifications(g *mirror.Service, collection string) error {
	err := g.Subscriptions.Delete(collection).Do()
	if err != nil {
		fmt.Printf("An error occurred: %v\n", err)
		return err
	}
	return nil
}

原始 HTTP

並未使用用戶端程式庫。

DELETE /mirror/v1/subscriptions/timeline HTTP/1.1
Authorization: Bearer auth token