I am developing my first facebook app, which includes creating a new album and posting photos to the user wall.
By learning through facebook documentation and few tutorial and came up this code, but I am getting following error with it.
Fatal error: Call to a member function setFileUploadSupport() on a non-object …
$facebook -> setFileUploadSupport(true);
$album_details = array('message' => 'Album desc', 'name' => 'Album name');
$create_album = $facebook -> api('/me/albums', 'post', $album_details);
$album_uid = $create_album['id'];
$photo_details = array('message' => 'Photo message');
$file = 'app.jpg';
$photo_details['image'] = '@' . realpath($file);
$upload_photo = $facebook -> api('/' . $album_uid . '/photos', 'post', $photo_details);
Kindly help me with this. thankyou
You will need instantiate the class with file upload support and request the correct permissions.
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'fileUpload' => true // enable file upload support
));
// get a login url with the correct perms
$facebook->getLoginUrl(array(
'scope' => 'photo_upload,first_name,email,publish_stream,read_stream'
));
photo_upload is the key permission here, allowing you to upload photos.
Have you instantiated your variable ($facebook) as the object-class?
Example:
include('class.Facebook.php');
$facebook = new Facebook();
You need you instantiate the class by creating a new object first. You also need to pass a $config array - as the constructor is 'missing 1 argument'; that's the error that you're getting.
// Create facebook object.
$config = array(
'appId' => 'app id',
'secret' => 'app secret',
'fileUpload' => true
);
// Initiate the library
$facebook = new Facebook($config);
Replace the 'app id' and 'app secret' with the one you obtained upon creating your facebook application.
Edit: Added a small change in the code. The $config takes a third optional element in an array, called fileUpload (a boolean indicating if file uploads are enabled). You need to set this because you call the setFileUploadSupport() method. Or the other way is to write is as you did and pass the boolean value directly in setFileUploadSupport(true). Either way works.