Issue
I manage 4 Facebook fan pages. Whenever users make a news on his website, I post it on Facebook. Now I have made it that I only have to press a button and the news were posted. I would like to automate this. How can I do this? My problem is that it is associated with my Facebook account and then it is not running in cron job or nothing is posted. Can I use my login data to a file which the Cronjob can always log in?
Solution
Basically you need a script to retrieve & store the infos needed to have a permanent access.
First you'll need to get permanent access tokens for your pages :
- Get user to allow app with appropriate permissions
- Retreive user access token
- Change user access token for extended user access token
Here is how I do this step (you could also use curl)
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUT_APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=OLD_TOKEN";
$accessToken = @file_get_contents($token_url);
- Query /me/accounts with user extended access token to get the pages
- Change pages access tokens for extended access tokens (same code as above) (edit: this step is now outdated as querying /accounts with an extended user token grants an extended page token)
Just store the pages ids, extended access token & whatever you like then retrieve them to make your API call in your publish script.
You can even post on multiple pages from multiple facebook users that way :)
Concerning the cron job, you don't need it anymore as long as you don't need really frequent reposts. You can schedule the post on facebook via their API from the current date up to 6 month.
$attachements = array(
'access_token' => $page->getToken(),
'message' => 'MY MESSAGE',
'scheduled_publish_time' => THE_TIMESTAMP,
'published' => false
);
Answered By - Tom Tom
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.