I am looking to update a facebook company page directly using cron and php.
Can anyone shed some light on the simplest current correct method of generating a page access token then extending that so that I may use that in my php script that I will run by cron?
I just want to write two simple php scripts, one that generates this extended page token by me opening that page within a browser monthly, and the other which would be executed by cron using that page token for automatic authentication independent of a users browser (I want my server to authenticate by itself) to post a simple text message to a company page that I am an admin of.
I am just looking to send short messages at particular times to the company page direct from the server without a person having to be involved.
Thanks
First of all, as you need to post to your company's Page, then you would require Page Access Token and coincidentally it never expires onece generated.
First you will have to implement login
feature of Facebook along with extended permission manage_pages
permission. The easiest and fastest way to do the same would be to create an App and then using Graph Explorer with the app selected, generate access token with the manage_pages
permission. If you want to implement the same you might want to look at this example.
Edit: When using Graph Explorer you would be required to navigate to /me/accounts
end point, there you would find the required access token for the page in question along with other pages you might administer.
After you have obtained the Page Access Token, you may then use the same to perform the posting of update using the PHP SDK's api
method after you have set the access token of your Page in the SDK with setAccessToken()
. Or you may just perform a HTTP POST with your message
to your page at the endpoint
https://graph.facebook.com/pageID/feed?access_token=Your_page_access_token