I am developing a program to add a photo album to a company web-site and simultaneously post it to the company's facebook page. So far, the web-site album post works well, but I'm having issues posting it to facebook. I am using the new SDK 4, have set up an app in facebook under the admin's facebook page, and successfully created a session that can get all of the company album information, but when I try to POST a new album to the business page, I get this error:
'Facebook\FacebookAuthorizationException' with message '(#100) Invalid ID for album owner'
I have been having problems finding anything helpful on the facebook developer web-site, can anyone here point me in the right direction? Here is my code:
<?php
require_once("php/facebook/autoload.php");
session_start();
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// start session
// init app with app id and secret
FacebookSession::setDefaultApplication( 'APP_ID','SECRET' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('test.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/BUSINESS PAGE ID/albums' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$request = new FacebookRequest(
$session,
'POST',
'/BUSINESS PAGE ID/albums',
array (
'name' => 'Test Album',
'message' => 'This is for testing purposes only',
)
);
$newAlbumID = $request->execute();
// print data
echo 'New Album ID: '.$newAlbumID.'<br />';
//echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}
?>
Any help would be greatly appreciated. Thanks!