Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active April 8, 2017 09:50
Show Gist options
  • Save niraj-shah/9514525 to your computer and use it in GitHub Desktop.
Save niraj-shah/9514525 to your computer and use it in GitHub Desktop.
Script to upload a photo and set it as the cover image for a Facebook Page
<?php
// include Facebook PHP SDK
include "facebook/facebook.php";
// init Facebook SDK with app settings
$facebook = new Facebook( array( 'appId' => APP_ID, 'secret' => APP_SECRET ) );
// enable file upload support
$facebook->setFileUploadSupport( true );
// set the page access token
$facebook->setAccessToken( PAGE_TOKEN );
// upload a photo to facebook, will return id of uploaded photo
$photo_uploaded = $facebook->api( $page_id . "/photos", "POST", array(
'source' => '@' . 'cover.png',
'no_story' => true // suppress automatic image upload story, optional
) );
// set uploaded photo as cover image, will return true on success
$cover = $facebook->api( $page_id, "POST", array(
'cover' => $photo_uploaded['id'],
'offset_x' => 0, // optional
'offset_y' => 0, // optional
'no_feed_story' => true // suppress automatic cover image story, optional
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment