图谱 API 版

Ad Account Ads

Ads belonging to this ad account.

读取

Ads belonging to this ad account

图谱 API 探索工具
GET /v21.0/act_{ad-account-id}/ads 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(
    '/act_{ad-account-id}/ads',
    '{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 */
FB.api(
    "/act_{ad-account-id}/ads",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/act_{ad-account-id}/ads",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/act_{ad-account-id}/ads"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

参数

参数描述
date_preset
enum{today, yesterday, this_month, last_month, this_quarter, maximum, data_maximum, last_3d, last_7d, last_14d, last_28d, last_30d, last_90d, last_week_mon_sun, last_week_sun_sat, last_quarter, last_year, this_week_mon_today, this_week_sun_today, this_year}

Predefine date range used to aggregate insights metrics

effective_status
list<string>

Filter ads by effective status

time_range
{'since':YYYY-MM-DD,'until':YYYY-MM-DD}

Date range used to aggregate insights metrics

since
datetime

A date in the format of "YYYY-MM-DD", which means from the beginning midnight of that day.

until
datetime

A date in the format of "YYYY-MM-DD", which means to the beginning midnight of the following day.

updated_since
integer

Time since the Ad has been updated.

字段

从这条连线读取将返回一个 JSON 格式的结果:

{ "data": [], "paging": {}, "summary": {} }

data

Ad 节点列表。

paging

详细了解分页功能,请见图谱 API 指南

summary

关于连线的汇总信息(例如次数总计)。请指定字段来调取概要中的参数(例如:概要=insights)。

字段说明
insights
Edge<AdsInsights>

Analytics summary for all objects

total_count
unsigned int32

Total number of Ads returned by the query

错误代码

错误描述
100Invalid parameter
190Invalid OAuth 2.0 Access Token
80004There have been too many calls to this ad-account. Wait a bit and try again. For more info, please refer to https://developers.facebook.com/docs/graph-api/overview/rate-limiting#ads-management.
200Permissions error
80000There have been too many calls from this ad-account. Wait a bit and try again. For more info, please refer to https://developers.facebook.com/docs/graph-api/overview/rate-limiting#ads-insights.
3018The start date of the time range cannot be beyond 37 months from the current date
2500Error parsing graph query
2642Invalid cursors values

创建

你可以通过下列路径向 ads 连线发出 POST 请求:
发布到这个连线会创建 an Ad

例子

Graph API Explorer
POST /v21.0/act_<AD_ACCOUNT_ID>/ads HTTP/1.1
Host: graph.facebook.com

name=My+Ad&adset_id=%3CAD_SET_ID%3E&creative=%7B%22creative_id%22%3A%22%3CCREATIVE_ID%3E%22%7D&status=PAUSED
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/act_<AD_ACCOUNT_ID>/ads',
    array (
      'name' => 'My Ad',
      'adset_id' => '<AD_SET_ID>',
      'creative' => '{"creative_id":"<CREATIVE_ID>"}',
      'status' => 'PAUSED',
    ),
    '{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 */
FB.api(
    "/act_<AD_ACCOUNT_ID>/ads",
    "POST",
    {
        "name": "My Ad",
        "adset_id": "<AD_SET_ID>",
        "creative": "{\"creative_id\":\"<CREATIVE_ID>\"}",
        "status": "PAUSED"
    },
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
Bundle params = new Bundle();
params.putString("name", "My Ad");
params.putString("adset_id", "<AD_SET_ID>");
params.putString("creative", "{\"creative_id\":\"<CREATIVE_ID>\"}");
params.putString("status", "PAUSED");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/act_<AD_ACCOUNT_ID>/ads",
    params,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"name": @"My Ad",
  @"adset_id": @"<AD_SET_ID>",
  @"creative": @"{\"creative_id\":\"<CREATIVE_ID>\"}",
  @"status": @"PAUSED",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/act_<AD_ACCOUNT_ID>/ads"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];
curl -X POST \
  -F 'name="My Ad"' \
  -F 'adset_id="<AD_SET_ID>"' \
  -F 'creative={
       "creative_id": "<CREATIVE_ID>"
     }' \
  -F 'status="PAUSED"' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/ads
如果你希望详细了解如何使用图谱 API,请阅读我们的图谱 API 指南

参数

参数描述
ad_schedule_end_time
datetime

An optional parameter that defines the end time of an individual ad. If no end time is defined, the ad will run on the campaign’s schedule.

This parameter is only available for sales and app promotion campaigns.

ad_schedule_start_time
datetime

An optional parameter that defines the start time of an individual ad. If no start time is defined, the ad will run on the campaign’s schedule.

This parameter is only available for sales and app promotion campaigns.

adlabels
list<Object>

Ad labels associated with this ad

adset_id
int64

The ID of the ad set, required on creation.

adset_spec
Ad set spec

The ad set spec for this ad. When the spec is provided, adset_id field is not required.

audience_id
string

The ID of the audience.

bid_amount
integer

Deprecated. We no longer allow setting the bid_amount value on an ad. Please set bid_amount for the ad set.

conversion_domain
string

The domain where conversions happen. Required to create or update an ad in a campaign that shares data with a pixel. This field will be auto-populated for existing ads by inferring from destination URLs . Note that this field should contain only the first and second level domains, and not the full URL. For example facebook.com.

creative
AdCreative

This field is required for create. The ID or creative spec of the ad creative to be used by this ad. You can read more about creatives here. You may supply the ID within an object as follows:

{"creative_id": <CREATIVE_ID>}
or creative spec as follow:

{"creative": {\"name\": \"<NAME>\", \"object_story_spec\": <SPEC>}}

必填支持表情符号
creative_asset_groups_spec
string (CreativeAssetGroupsSpec)

creative_asset_groups_spec

支持表情符号
date_format
string

The format of the date.

display_sequence
int64

The sequence of the ad within the same campaign

draft_adgroup_id
numeric string or integer

The ID of the draft ad.

engagement_audience
boolean

Flag to create a new audience based on users who engage with this ad

execution_options
list<enum{validate_only, synchronous_ad_review, include_recommendations}>
默认值:Set

An execution setting
validate_only: when this option is specified, the API call will not perform the mutation but will run through the validation rules against values of each field.
include_recommendations: this option cannot be used by itself. When this option is used, recommendations for ad object's configuration will be included. A separate section recommendations will be included in the response, but only if recommendations for this specification exist.
synchronous_ad_review: this option should not be used by itself. It should always be specified with validate_only. When these options are specified, the API call will perform Ads Integrity validations, which include message language checking, image 20% text rule, and so on, as well as the validation logics.
If the call passes validation or review, response will be {"success": true}. If the call does not pass, an error will be returned with more details. These options can be used to improve any UI to display errors to the user much sooner, e.g. as soon as a new value is typed into any field corresponding to this ad object, rather than at the upload/save stage, or after review.

include_demolink_hashes
boolean

Include the demolink hashes.

name
string

Name of the ad.

必填支持表情符号
priority
int64

Priority

source_ad_id
numeric string or integer

ID of the source Ad, if applicable.

status
enum{ACTIVE, PAUSED, DELETED, ARCHIVED}

Only ACTIVE and PAUSED are valid during creation. Other statuses can be used for update. When an ad is created, it will first go through ad review, and will have the ad status PENDING_REVIEW before it finishes review and reverts back to your selected status of ACTIVE or PAUSED. During testing, it is recommended to set ads to a PAUSED status so as to not incur accidental spend.

tracking_specs
Object

With Tracking Specs, you log actions taken by people on your ad. See Tracking and Conversion Specs.

返回类型

这个端点支持先写后读,并会读取返回类型中 id 代表的节点。
Struct {
id: numeric string,
success: bool,
}

错误代码

错误描述
100Invalid parameter
200Permissions error
2626The request for a reach frequency campaign has failed.
105The number of parameters exceeded the maximum for this operation
194Missing at least one required parameter
368The action attempted has been deemed abusive or is otherwise disallowed
80004There have been too many calls to this ad-account. Wait a bit and try again. For more info, please refer to https://developers.facebook.com/docs/graph-api/overview/rate-limiting#ads-management.
190Invalid OAuth 2.0 Access Token
500Message contains banned content
2632Failed to upload match metadata

更新

你无法在此端点执行该操作。

删除

你无法在此端点执行该操作。