Search code examples
facebookfacebook-graph-apipublishfacebook-comments

Facebook api can't get publish stream with long lived access token


I was succesful to get a never expiring access token for my facebook page. I worked well when i wanted to get posts from my facebook page. But when i want to publish a comment from a page outside my facebook page, an error "permission" appeared:

Fatal error: Uncaught exception 'Facebook\FacebookPermissionException' with message '(#200) 
The user hasn't authorized the application to perform this action' in /var/www/dev/test/Facebook/FacebookRequestException.php:128 Stack trace: #0 /var/www/dev/test/Facebook/FacebookRequest.php(261): Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 403) #1 /var/www/dev/test/facebook.php(164): Facebook\FacebookRequest->execute() #2 {main} thrown in /var/www/dev/test/Facebook/FacebookRequestException.php on line 128

I found some articles and all of them give me a solution that i must use getLoginUrl to get a link, click on it to connect to facebook and accept some permissions... Like that:

$permissions = array('manage_pages','publish_stream');

// Get login URL
$loginUrl = $helper->getLoginUrl($permissions);

Here it's the doc of this function "getLoginUrl":

This method returns a URL that, when clicked by the user on the client-side, will redirect the user to login to Facebook and authorize your application, if necessary. It will then redirect back to your application. If the user did not successfully log in, or did not authorize your application, the user will be redirected via an HTTP 302 redirect to your redirect_uri with error, error_reason, and error_description parameters in the URL. See the authentication page for details.

Is it possible to have an access token and use it to connect to facebook automatically (users don't need to do anything, just send comment from my page (outside of fb))?

Note: In my case, all users would use one account (this is my account) to post to my facebook page's wall. They don't need to sign in to their account. And on my facebook page's wall, all of comments would be displayed "posted by me".

Thanks


Solution

  • Why don't you include the publish_actions permission in your Page Access Token (see https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed/#publish)? Then you should be able to use this token also to post to the Page's wall.

    Keep in mind that those Posts will not appear with the User's name, but with the name of the Page and therefore will look "official"...