图谱 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
}

否则系统会返回相关的错误消息。

更新

您可以使用新值执行发布操作,在此连线上执行更新。如此便可在不覆盖现有字段的情况下,修改特定主题的订阅。