Reputation: 1577
I have a facebook application, and a facebook (fan) page. I want to publish to the page, authentified as the app (if possible), from a php script run periodically as a cron job.
I'm using the official facebook php sdk.
I am trying to post to the page with $facebook->api($pageId."/feed", 'POST', $post);
, where $post contains the required message
and link
keys, and should also contain access_token
.
To get the access token, I tried using $facebook->getApplicationAccessToken()
, and making a curl request to https://graph.facebook.com/oauth/access_token
(same result).
The response I get is:
OAuthException: (#200): The user hasn't authorized the application to perform this action
I was able to post to the page, but with an access_token from https://graph.facebook.com/me/accounts
, which required me to provide a user's access token in the first place. The user's and and his page's tokens seem to expire, at most after 60 days, so this solution is not good.
I tried granting permissions like explained here Authorizing a Facebook Fan Page for Status Updates, but I still get the error from before.
Any solution on how to post to a facebook page which does not involve user login will be welcome!
Upvotes: 0
Views: 2149
Reputation: 705
You can get the required access_token for posting to a facebook page via an application using the Graph API Explorer. In the Explorer:
Upvotes: 1
Reputation: 25938
It is not possible to post on Page using Application access_token
and without logging user in (at least once to get an access_token
, later it can be extended) and requesting appropriate permissions.
To publish to Page as User you need publish_stream
permission granted by User.
To publish to Page as Page you need publish_stream
and manage_pages
permissions granted by User and Page access_token
which can be retrieved from accounts
connection of user
.
Upvotes: 3