Page Management

Learn how to create pages, update pages, and manage Page content.

Endpoints & Webhooks

Refer to each endpoint's reference documentation for parameter and permission requirements.

Create a Page

Requirements

  • The person requesting the access token must have manage_pages permissions
  • Page Fields:
    • about
    • category_enum
    • cover_photo with url
    • name
    • picture

Sample Code

$fields = array(
);
$params = array(
  'name' => 'My Personal Blog',
  'category_enum' => 'PERSONAL_BLOG',
  'about' => 'Just trying some things with the API',
  'picture' => 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
  'cover_photo' => array('url' => 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'),
  'location' => array('city' => 'Seattle', 'country' => 'US', 'state' => 'WA'),
  'address' => '1101 Dexter Ave N',
);
(new User(<USER_ID>_for_page))->createAccount(
  $fields,
  $params
);
fields = [
]
params = {
    'name': 'My Personal Blog',
    'category_enum': 'PERSONAL_BLOG',
    'about': 'Just trying some things with the API',
    'picture': 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
    'cover_photo': {'url':'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
    'location': {'city':'Seattle', 'country':'US', 'state':'WA'},
    'address': '1101 Dexter Ave N',
}
User(user_id_for_page).create_account(
    fields=fields,
    params=params,
)
new User(user_id_for_page, context).createAccount()
  .setName("My Personal Blog")
  .setCategoryEnum("PERSONAL_BLOG")
  .setAbout("Just trying some things with the API")
  .setPicture("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png")
  .setCoverPhoto("{\"url\":\"https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png\"}")
  .setLocation("{\"city\":\"Seattle\", \"country\":\"US\", \"state\":\"WA\"}")
  .setAddress("1101 Dexter Ave N")
  .execute();
user = FacebookAds::User.get(user_id_for_page)
user.accounts.create({
name: 'My Personal Blog',
category_enum: 'PERSONAL_BLOG',
about: 'Just trying some things with the API',
picture: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
cover_photo: {'url':'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
location: {'city':'Seattle', 'country':'US', 'state':'WA'},
address: '1101 Dexter Ave N',
})
fields = [
];
params = {
  'name' : 'My Personal Blog',
  'category_enum' : 'PERSONAL_BLOG',
  'about' : 'Just trying some things with the API',
  'picture' : 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
  'cover_photo' : {'url':'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
  'location' : {'city':'Seattle', 'country':'US', 'state':'WA'},
  'address' : '1101 Dexter Ave N',
};
await (new User(<USER_ID>_for_page)).createAccount(
  fields,
  params
);

On success, Graph API responds with JSON containing the Post ID:

{
  "id": "2011725632410952"
}

Learn more

See the Reference documentation for more information on creating pages, including caveats about adding a location.

Update a Page

Update a Page with new Page information such as website, phone, number, or location.

Requirements

Sample Code

The following example is updating the description, about, website, phone, and location of a Page.

$fields = array(
);
$params = array(
  'description' => 'This is an awesome cafe!',
  'about' => 'about my interest',
  'website' => 'www.facebook.com',
  'phone' => '2061234567',
  'location' => array('city' => 'Seattle', 'country' => 'US', 'state' => 'WA'),
);
(new Page(<PAGE_ID>))->updateSelf(
  $fields,
  $params
);
fields = [
]
params = {
    'description': 'This is an awesome cafe!',
    'about': 'about my interest',
    'website': 'www.facebook.com',
    'phone': '2061234567',
    'location': {'city':'Seattle', 'country':'US', 'state':'WA'},
}
Page(<PAGE_ID>).api_update(
    fields=fields,
    params=params,
)
new Page(<PAGE_ID>, context).update()
  .setDescription("This is an awesome cafe!")
  .setAbout("about my interest")
  .setWebsite("www.facebook.com")
  .setPhone("2061234567")
  .setLocation("{\"city\":\"Seattle\", \"country\":\"US\", \"state\":\"WA\"}")
  .execute();
page = FacebookAds::Page.get(<PAGE_ID>)
page.description = 'This is an awesome cafe!'
page.about = 'about my interest'
page.website = 'www.facebook.com'
page.phone = '2061234567'
page.location = {'city':'Seattle', 'country':'US', 'state':'WA'}
page.save
fields = [
];
params = {
  'description' : 'This is an awesome cafe!',
  'about' : 'about my interest',
  'website' : 'www.facebook.com',
  'phone' : '2061234567',
  'location' : {'city':'Seattle', 'country':'US', 'state':'WA'},
};
await (new Page(<PAGE_ID>)).update(
  fields,
  params
);

On success, Graph API responds with JSON containing the Post ID:

{
  "success": true
}

Create a Page Post

Requirements to Post as a Page

Requirements to Post as an Individual

Sample Code to Publish a Post

$fields = array(
);
$params = array(
  'message' => 'This is a test message',
);
$post = (new Page(<PAGE_ID>))->createFeed(
  $fields,
  $params
);
$post_id = $post->id;
$fields = array(
);
$params = array(
);
(new PagePost($post_id))->deleteSelf(
  $fields,
  $params
);
fields = [
]
params = {
    'message': 'This is a test message',
}
post = Page(<PAGE_ID>).create_feed(
    fields=fields,
    params=params,
)
post_id = post.get_id()
fields = [
]
params = {
}
PagePost(post_id).api_delete(
    fields=fields,
    params=params,
)
PagePost post = new Page(<PAGE_ID>, context).createFeed()
  .setMessage("This is a test message")
  .execute();
String post_id = post.getId();
new PagePost(post_id, context).delete()
  .execute();
page = FacebookAds::Page.get(<PAGE_ID>)
post = page.feed.create({
message: 'This is a test message',
})
post_id = post.id
print 'post_id:', post_id
page_post = FacebookAds::PagePost.get(post_id)
page_post.destroy({
})
fields = [
];
params = {
  'message' : 'This is a test message',
};
let post = await (new Page(<PAGE_ID>)).createFeed(
  fields,
  params
);
let post_id = post.id;
fields = [
];
params = {
};
await (new PagePost(post_id)).delete(
  params
);

On success, Graph API responds with JSON containing the Post ID:

{
  "id": 1353269864728879_1661203157268880"
}

Sample Code to Post a Photo

$api = Api::init($app_id, null, $page_access_token);
$fields = array(
);
$params = array(
  'url' => 'https://www.facebook.com/images/fb_icon_325x325.png',
  'published' => 'false',
);
$photo_to_be_post = (new Page($page_id))->createPhoto(
  $fields,
  $params
);
$photo_to_be_post_id = $photo_to_be_post->id;
$fields = array(
  'object_id',
);
$params = array(
  'message' => 'I have something good for you!',
  'attached_media' => array(array('media_fbid' =>  $photo_to_be_post_id)),
);
$feed_post_with_image = (new Page($page_id))->createFeed(
  $fields,
  $params
);
$feed_post_with_image_id = $feed_post_with_image->id;
$fields = array(
);
$params = array(
);
(new PagePost($feed_post_with_image_id))->deleteSelf(
  $fields,
  $params
);
FacebookAdsApi.init(access_token=page_access_token)
fields = [
]
params = {
    'url': 'https://www.facebook.com/images/fb_icon_325x325.png',
    'published': 'false',
}
photo_to_be_post = Page(page_id).create_photo(
    fields=fields,
    params=params,
)
photo_to_be_post_id = photo_to_be_post.get_id()
fields = [
    'object_id',
]
params = {
    'message': 'I have something good for you!',
    'attached_media': [{'media_fbid': photo_to_be_post_id}],
}
feed_post_with_image = Page(page_id).create_feed(
    fields=fields,
    params=params,
)
feed_post_with_image_id = feed_post_with_image.get_id()
fields = [
]
params = {
}
PagePost(feed_post_with_image_id).api_delete(
    fields=fields,
    params=params,
)
context = new APIContext(page_access_token).enableDebug(false);
Photo photoToBePost = new Page(page_id, context).createPhoto()
  .setUrl("https://www.facebook.com/images/fb_icon_325x325.png")
  .setPublished(false)
  .execute();
String photo_to_be_post_id = photoToBePost.getId();
PagePost feedPostWithImage = new Page(page_id, context).createFeed()
  .setMessage("I have something good for you!")
  .setAttachedMedia("[{\'media_fbid\': " + photo_to_be_post_id + "}]")
  .requestField("object_id")
  .execute();
String feed_post_with_image_id = feedPostWithImage.getId();
new PagePost(feed_post_with_image_id, context).delete()
  .execute();
FacebookAds::Session.default_session.access_token = page_access_token
page = FacebookAds::Page.get(page_id)
photo_to_be_post = page.photos.create({
url: 'https://www.facebook.com/images/fb_icon_325x325.png',
published: 'false',
})
photo_to_be_post_id = photo_to_be_post.id
print 'photo_to_be_post_id:', photo_to_be_post_id
feed_post_with_image = page.feed.create({
message: 'I have something good for you!',
attached_media: [{'media_fbid': photo_to_be_post_id}],
})
feed_post_with_image_id = feed_post_with_image.id
print 'feed_post_with_image_id:', feed_post_with_image_id
page_post = FacebookAds::PagePost.get(feed_post_with_image_id)
page_post.destroy({
})
bizSdk.FacebookAdsApi.init(page_access_token);
fields = [
];
params = {
  'url' : 'https://www.facebook.com/images/fb_icon_325x325.png',
  'published' : 'false',
};
let photo_to_be_post = await (new Page(page_id)).createPhoto(
  fields,
  params
);
let photo_to_be_post_id = photo_to_be_post.id;
fields = [
  'object_id',
];
params = {
  'message' : 'I have something good for you!',
  'attached_media' : [{'media_fbid': photo_to_be_post_id}],
};
let feed_post_with_image = await (new Page(page_id)).createFeed(
  fields,
  params
);
let feed_post_with_image_id = feed_post_with_image.id;
fields = [
];
params = {
};
await (new PagePost(feed_post_with_image_id)).delete(
  params
);

On success, Graph API responds with JSON containing the Post ID:

{
  "id": 1353269864728879_1661203157268880"
}

Sample Code to Post a Link

$fields = array(
);
$params = array(
  'link' => 'www.facebook.com',
);
$post = (new Page(<PAGE_ID>))->createFeed(
  $fields,
  $params
);
$post_id = $post->id;
fields = [
]
params = {
    'link': 'www.facebook.com',
}
post = Page(<PAGE_ID>).create_feed(
    fields=fields,
    params=params,
)
post_id = post.get_id()
PagePost post = new Page(<PAGE_ID>, context).createFeed()
  .setLink("www.facebook.com")
  .execute();
String post_id = post.getId();
page = FacebookAds::Page.get(<PAGE_ID>)
post = page.feed.create({
link: 'www.facebook.com',
})
post_id = post.id
print 'post_id:', post_id
fields = [
];
params = {
  'link' : 'www.facebook.com',
};
let post = await (new Page(<PAGE_ID>)).createFeed(
  fields,
  params
);
let post_id = post.id;

On success, Graph API responds with JSON containing the Post ID:

{
  "id": "1353269864728879_1661203157268880"
}

Update a Page Post

Requirements

Sample Code to Update a Post

$fields = array(
);
$params = array(
  'message' => 'This is a test message',
);
$post = (new PagePost(<OBJECT_STORY_ID>))->updateSelf(
  $fields,
  $params
);
fields = [
]
params = {
    'message': 'This is a test message',
}
post = PagePost(<OBJECT_STORY_ID>).api_update(
    fields=fields,
    params=params,
)
PagePost post = new PagePost(<OBJECT_STORY_ID>, context).update()
  .setMessage("This is a test message")
  .execute();
page_post = FacebookAds::PagePost.get(<OBJECT_STORY_ID>)
page_post.message = 'This is a test message'
page_post.save
fields = [
];
params = {
  'message' : 'This is a test message',
};
let post = await (new PagePost(<OBJECT_STORY_ID>)).update(
  fields,
  params
);

On success, Graph API responds with JSON containing the Comment ID:

{
  "id": "1661203157268880_1661364040586125"
}

Learn More about Webhooks

Please review to the Webhooks product documentation for information on implementing webhooks for Pages.