Aleksa Aleksa - 5 days ago 5
PHP Question

Facebook graph: Post picture as page not as user

I'm using FB App to publish posts to my FB pages.
So when i use this code for links, it works.

$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true
));

$attachment = array(
'access_token' => $row["token"],
'name' => $_POST["name"],
'picture' => $_POST["picture"],
'message' => $_POST["message"],
'link' => $_POST["link"]);
try
{
$facebook->api("/".$row['id']."/feed", "POST", $attachment);
}

catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}


But, when i want to share pictures as a page:

$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
'fileUpload' => true,
'allowSignedRequest' => false
));

$attachment = array('access_token' => $row["token"], 'url' => 'http://image.link.jpg', 'message' => $_POST["message"]);
try
{
$facebook->api("/".$row['id']."/photos", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}


The app post picture as user. USER to PAGE.
So i found that i need to use publish_pages permission, but my access token contains both publish_actions and publish_pages. I can't change that because I'm using one access token for a lot of things.

enter image description here

So i have to ask, is there a way to explicitly choose what permissions i want to use from access token. FB API have same code for page and user picture publish /user_id/photos and /page_id/photos.

Answer

Need to use Page access token, there's no other way.

Comments