圖形 API 版本

/{app-id}/subscriptions

此關係連線可讓您在應用程式中設定 Webhooks 訂閱。

讀取

圖形 API 測試工具
GET /v19.0/{app-id}/subscriptions HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/{app-id}/subscriptions',
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/subscriptions",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/subscriptions"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

權限

  • 必須取得應用程式存取權杖,才能傳回該應用程式的訂閱。

欄位

名稱 說明 類型

object

指示此訂閱套用的物件類型。

enum{user, page, permissions, payments}

callback_url

觸發更新時,會收到 POST 要求的網址。

string

fields

在此 object 中訂閱的欄位組合。

string[]

active

顯示訂閱是否有效。

bool

建立

您可以使用下列關係連線建立新的 Webhooks 訂閱:

POST /v19.0/{app-id}/subscriptions HTTP/1.1
Host: graph.facebook.com

object=page&callback_url=http%3A%2F%2Fexample.com%2Fcallback%2F&fields=about%2C+picture&include_values=true&verify_token=thisisaverifystring
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/{app-id}/subscriptions',
    array (
      'object' => 'page',
      'callback_url' => 'http://example.com/callback/',
      'fields' => 'about, picture',
      'include_values' => 'true',
      'verify_token' => 'thisisaverifystring',
    ),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
Bundle params = new Bundle();
params.putString("object", "page");
params.putString("callback_url", "http://example.com/callback/");
params.putString("fields", "about, picture");
params.putString("include_values", "true");
params.putString("verify_token", "thisisaverifystring");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/subscriptions",
    params,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"object": @"page",
  @"callback_url": @"http://example.com/callback/",
  @"fields": @"about, picture",
  @"include_values": @"true",
  @"verify_token": @"thisisaverifystring",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/subscriptions"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

使用 callback_urlverify_tokenobject 欄位發出 POST 要求會重新啟用訂閱。

限制

權限

  • 必須取得應用程式存取權杖,才能為該應用程式新增訂閱。
  • 物件類型 user 的訂閱僅適用於已安裝應用程式的用戶。
  • 物件類型 page 的訂閱僅適用於已安裝應用程式的粉絲專頁。您可以使用 /{page-id}/subscribed_apps 關係連線為粉絲專頁安裝應用程式。
  • 用於訂閱的應用程式必須設定為接收 Webhooks 更新

欄位

名稱 說明 類型

object

指示此訂閱套用的物件類型。

enum{user, page, permissions, payments}

callback_url

觸發更新時會收到 POST 要求,以及嘗試執行此發佈操作時會收到 GET 要求的網址。若要瞭解如何建構回呼網址頁面,請參閱相關指南

string

fields

要在此 object 中訂閱的一或多個有效欄位組合

string[]

include_values

顯示變更通知是否應包含新值。

bool

verify_token

可用來向伺服器確認要求有效的任意字串。

string

回應

如果回呼網址有效且訂閱成功,就會出現以下內容:

{
  "success": true
}

否則會傳回相關錯誤訊息。

刪除

您可以透過以下操作刪除所有訂閱或每個物件的訂閱:

DELETE /v19.0/{app-id}/subscriptions HTTP/1.1
Host: graph.facebook.com

object=page
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->delete(
    '/{app-id}/subscriptions',
    array (
      'object' => 'page',
    ),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
Bundle params = new Bundle();
params.putString("object", "page");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/subscriptions",
    params,
    HttpMethod.DELETE,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"object": @"page",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/subscriptions"
                                      parameters:params
                                      HTTPMethod:@"DELETE"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

若要從訂閱中刪除特定欄位,可以加入 fields 參數。

權限

  • 您必須取得應用程式存取權杖,才能刪除該應用程式的訂閱。

欄位

名稱 說明 類型

object

要移除訂閱的特定物件類型。如果沒有包含此選填欄位,則系統將移除此應用程式的所有訂閱。

enum{user, page, permissions, payments}

fields

要在此 object 中訂閱的一或多個有效欄位組合

string[]

回應

如果成功,回應如下:

{
  "success": true
}

否則會傳回相關錯誤訊息。

更新

若要在此關係連線上執行更新作業,請使用新值進行發佈操作。如此一來,系統就會直接修改指定主題的訂閱,而不會覆寫現有欄位。