Reputation: 82
I have a problem uploading photos to an album on a facebook page. Uploading a photo to the page is no problem but with the album it doesn't work.
Here's the code (copied from an example):
<?php
session_start();
require_once 'vendor/facebook/php-sdk-v4/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('app_id','app-secret');
$scope = array('publish_actions');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'url' );
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 ) ) {
/* make the API call */
$request = new FacebookRequest(
$session,
'POST',
'/page-id/albums?name=albumname/photos',
array (
'url' => 'url',
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}
When i try this i get the message: Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#100) Invalid ID for album owner' in...
Does anyone know whats going wrong?
Upvotes: 2
Views: 2815
Reputation: 96412
/page-id/albums?name=albumname
is for creating a new album with that name.
To publish a photo to an existing album, you have to post to /{album-id}/photos
.
See https://developers.facebook.com/docs/graph-api/reference/v2.1/album/photos#publish for more details.
Upvotes: 1