Posting a photo as an open graph facebook page

I have an application that has many open graph pages. I'm able to post as these pages just fine, except for photos. I get a "PHP Fatal error: Uncaught OAuthException: A user access token is required to request this resource." which makes no sense because I can post to the feed as the page no problem.

Heres the code:

require_once ('facebook.php');

$fb = new Facebook(array(
'appId'  => 'XXX',
'secret' => 'XXX',
));  

$fb->setFileUploadSupport(true);

$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath("testpic.jpg");

$data = $fb->api("/PAGEID/photos", "post", $args);

print_r($data);
?>

Is this possible to do without needing a user to login? I read that you can request the page access_token as a user, but it seems kind of dumb that you can use one way of authenticating for one function, then another way for another. I'd like to avoid an user logins if possible.

Answers


The app posting the photo needs to include in $args an access token for admin'ing the page. This is also called a "page access token" or "page token".

$args['access_token'] = $access_token;

The way I get such an access token is to obtain manage_pages,publish_stream permissions from the user (me) who is an admin of the page. Then:

$page_info = $facebook->api('/'.$PAGE_ID.'?fields=access_token');

and:

$access_token = $page_info['access_token'];

See also: Developer blog post


Need Your Help

Calculate rotation/translation matrix to match measurement points to nominal points

matrix computer-vision measurement point-cloud-library coordinate-transformation

I have two matrices, one containing 3D coordinates that are nominal positions per a CAD model and the other containing 3D coordinates of actual measured positions using a CMM. Every nominal point h...

angular directory slick execution

javascript angularjs mean-stack

I'm using the following plugin: http://vasyabigi.github.io/angular-slick/