0

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

Maven
  • 14,587
  • 42
  • 113
  • 174

3 Answers3

1

Have you instantiated your variable ($facebook) as the object-class?

Example:

include('class.Facebook.php');
$facebook = new Facebook();
  • oh thank you for replying, i just added it. but now i am getting this one warning and an error . `Warning: Missing argument 1 for Facebook::__construct(), called in /home/file.php on line 188 and defined in /home/facebook.php on line 35` | `Fatal error: Uncaught CurlException: 6: Couldn't resolve host 'graph.facebook.com' thrown in /home/base_facebook.php on line 886` – Maven Mar 06 '12 at 19:38
1

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.

mousesports
  • 509
  • 1
  • 6
  • 18
  • Thankyou, it ofcourse solved the argument missing error. but now i am getting a new error i.e.: `Fatal error: Uncaught OAuthException: Invalid OAuth access token signature. thrown in /home/base_facebook.php on line 1106` – Maven Mar 06 '12 at 20:22
  • if this relates to permission, then my auth url includes permissions for publishing the stream: `$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=first_name,email,publish_stream,read_stream";` Do i need some extra permission beside these? – Maven Mar 06 '12 at 20:28
  • There's an authentication issue. Try what SIR suggests here: http://stackoverflow.com/questions/6787173/facebook-access-token-problem – mousesports Mar 06 '12 at 20:29
  • Had you created a user variable to check whether or not the user is currently logged in? `$user = $facebook->getUser();`. It will return the user ID if the user is connected, 0 if not. – mousesports Mar 06 '12 at 20:36
  • **probably a problem** my `echo $facebook->getUser();` is returning '0' but I'm logged into facebook. Plus at the last am getting this error: `Fatal error: Uncaught OAuthException: Error validating application. Thrown in /home/ base_facebook.php on line 1106` – Maven Mar 07 '12 at 10:54
1

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.

eosgood
  • 318
  • 1
  • 9