Created
July 12, 2014 23:50
-
-
Save SecureCloud-biz/222cad0d980d3a048d8c 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Script to upload a photo by URL (i.e. remote resource) Use Above Script | |
// upload a photo to facebook by URL, will return id of uploaded photo | |
$photo_uploaded = $facebook->api( $page_id . "/photos", "POST", array( | |
'url' => 'http://healthhub.co/wp-content/uploads/2014/02/Group-Slider.jpg', // remote URL to image | |
'no_story' => true // suppress automatic image upload story, optional | |
) ); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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