Ben
Ben

Reputation: 21

Add an Album to Page using API (php)

I am trying to create an album for a page, however I get the following error;

[15-Sep-2011 22:38:14] PHP Fatal error: Uncaught OAuthException: (#100) Invalid ID for album owner thrown in C:\inetpub\wwwroot\Diveengine\v3\facebook\base_facebook.php on line 988

the code is as follows

require 'facebook.php';
$facebook = new Facebook(array(
    'appId'  => "aaaaaaaaaaaa",
    'secret' => "aaaaaaaaaaaaaaaaaaaaa",
));

$facebook->setAccessToken("aaaaaaaaaaaaaaaaaaaaa");

$me = $facebook->api('/me');


//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);



//Create an album
$album_details = array(
        'message'=> 'test album',
        'name'=> 'Test Album'
);
$create_album = $facebook->api('/pageid/albums', 'post', $album_details);
// I have the page ID

//Get album ID of the album you've just created
$album_uid = $create_album['id'];

I have been able to create an album for my profile, however I want this for the page.

Upvotes: 2

Views: 5315

Answers (1)

Jon McIntosh
Jon McIntosh

Reputation: 41

ok dude, it took long enough to figure this out, but here goes. Your code is probably fine, but the trick is getting the right access token. Originally, I thought I had to create a page access token (using the graph api explorer) with all the frills that would allow me to do what I wanted.

Turns out, all you need to do is this:

1) go to https://developers.facebook.com/tools/explorer 2) it'll probably auto populate your facebook id, but affix /accounts at the end there so it'll look like this:

#yourfacebookidnumber/accounts

or you can just change it to

https://graph.facebook.com/me/accounts

you'll get a JSON dump of a list of all the fan pages you're an administrator to. Find the fan page you want to post to (you need to be an administrator of that fan page).

Grab the access token specified there, use it in your code, and Bob's your uncle!

Upvotes: 4

Related Questions