Graph API 版本

/{app-id}/subscriptions

您可透過此關係連線配置應用程式上的 Webhooks 訂閱。

讀取

Graph 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 edge 為專頁安裝應用程式。
  • 用於訂閱的應用程式應設為接收 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
}

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

更新

您可以使用新值執行發佈操作,在此關係連線上執行更新。這樣將可修訂既定主題的訂閱,而不覆寫現有欄位。