Andrey
Andrey

Reputation: 1110

Facebook app can post messages on a fanpage wall but can't upload images

I've spent too many hours by now fighting with this, have read all I could find on this issue but no answer yet, please help.

I'm trying to post an image on a facebook page wall using a facebook app and Graph API:

<?php

$facebook = new Facebook(array(
          'appId'  => $this->settings['app_id'],
          'secret' => $this->settings['app_secret'],
          'fileUpload' => true,
));
$facebook->destroySession();
$filename = dirname(__FILE__) . '/upset.jpg';
$args = array(
    'message' => 'Test',
    'image' => '@' . realpath($filename),
    'access_token' => $this->settings['user_access_token'],
);
try {
    $result = $facebook->api($this->settings['fanpage_id'] . '/photos',
        'post', $args);
    var_dump($result);
}
catch(Exception $e) {
    echo $e->getType() . "\n" . $e->getMessage() . "\n";
}

This code REALLY POSTS a message to the page wall (when I replace '/photos' with '/feed'), and really posts a photo to the USER wall (when I change $this->settings['fanpage_id'] to $user_id) but not photo to the page wall.

It does upload the image though: the $result contains the id of the uploaded image and I can see it on facebook, but not in the page's album but in the user's.

P.S. I've tried to get the page access token with a call to /accounts - the same result. P.P.S. The user access token has manage_pages, photo_upload and other permissions (all but offline_access actually)

Upvotes: 1

Views: 742

Answers (2)

Andrey
Andrey

Reputation: 1110

Seems to be solved. I really needed to use the page access token instead of user, plus you don't need that "'no_story' => 1" in the parameters.

Upvotes: -1

Inam Abbas
Inam Abbas

Reputation: 1480

As it seems like you are using the access tocken of currently login facebook user then you might need to get manage_pages extended permission then once permission given you should be able to post image on fan page wall.

EDIT :

Extended permissions documentation here https://developers.facebook.com/docs/authentication/permissions/#page_perms Here is a tutorial available that shows how to get user login with extended permissions http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/

Upvotes: 2

Related Questions