I’m working on a small Facebook application. I created the application with the developer app – then I created the Facebook Page. Now I want to post some status messages on the page AS the page. Not with my username or someone else. My problem is, I don’t have rights to do that:
<?php
require "_facebook/facebook.php";
function getToken($appID, $appSecret)
{
return str_replace('access_token=', '', file_get_contents('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$appID.'&client_secret='.$appSecret));
}
$pAppID = 'XXXXX';
$pAppSec = 'XXXXX';
$pSiteID = 'XXXXX';
$pToken = getToken($pAppID, $pAppSec);
$pFacebook = new Facebook( array( 'appId' => $pAppID, 'secret' => $pAppSec ));
$args = array(
'access_token' => $pToken,
'method' => 'stream.publish',
'message' => "Test",
'target_id' => $pSiteID
);
$pRet = $pFacebook->api("/". $pSiteID ."/feed","post",$args);
var_dump($pRet);
?>
Sadly, I just get an error as a response “The user hasn’t authorized the application to perform this action“
My problem is, I am not able to use JavaScript to authenticate, I don’t want to connect with my real Facebook account also. Everything should be automatic. So help in any way would be great. I’m really stuck in here ..
Best regards
Check out this question: (i had an earlier answer here which was incorrect):
Posting to a Facebook Page as the Page (not a person)
The docs, if you want to implement this yourself are at
https://developers.facebook.com/docs/authentication/#pagelogin
Follow the instructions there to log in as the page
and then use the access token you have for the Page to make posts on that Page’s behalf.