SecureCloud-biz
7/12/2014 - 11:51 PM

Script to upload a photo and set it as the cover image for a Facebook Page

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
  ) );
  
?>