Ok so I finally managed to successfully link dynamic news posts on my website with my page's wall as Page (not user) through PHP. Still I'm wondering if my solution is correct, or if it'll work on the long-run. Having said that here's what I did:
- Created a profile to administrate the page
- Created the company page
- Created an app with the domain pointing to my site domain, and website pointing to my website url
- Disable offline_access deprecation in order to be able to issue offline_access tokens
- Found out my pageID through http:// graph.facebook.com/PAGE_NAME
- Went to https:// developers.facebook.com/tools/explorer/APP_ID
- Paste the pageID in the instead of the userID and clicked submit
- Then I clicked on get access token and checked manage_pages,publish_stream,offline_access
(when this alone didn't work, I visited https://developers.facebook.com/docs/authentication/ and under "Page Login" I found out that Page Login requires a different type of token...)
- Manually get token from https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages,publish_stream,offline_access&response_type=token
- redirect_uri in this case can be anything, we just wanted the url token parameter sent back
- Copy the token that is sent back from the URL (if it all went well the expires url param is set to 0 in the response)
- then I basically did this PHP script:
require_once('facebook-sdk/facebook.php');
//Required facebook auth vars
$appID = 'APP_ID';
$appSecret = 'APP_SECRET';
$pageID = 'PAGE_ID';
$appOfflineToken = 'TOKEN_RETURNED_IN_PREVIOUS_STEP';
$pageTokenURL = 'https://graph.facebook.com/me/accounts?access_token=';
$access_token = '';
//connect to facebook app
$facebook = new Facebook(array(
'appId' => $appID,
'secret' => $appSecret,
'cookie' => true
));
//get page managed pages information
$jsonData = file_get_contents($pageTokenURL.$appOfflineToken);
$content = json_decode($jsonData, true);
//filter access_token for desired page using pageID
foreach($content['data'] as $item) {
if($item['id'] == $pageID){
$access_token = $item['access_token'];
break;
}
}
//format post
$post = array(
'access_token' => $access_token,
'picture' => "http://URL_TO_PICTURE,
'link' => "http://URL_TO_NEWS_POST",
'name' => "NEWS_TITLE",
'description' => 'NEWS_DESCRIPTION'
);
//post content to page wall
$res = $facebook->api('/'.$pageID.'/feed', 'POST', $post);
so my question is ... even though this seems farfetched ... is it correct? well at least it works!
PS: sorry about the links but could only submit 2 in this post ... not enough street cred it seems :p
offline_access
will be deprecated in a few weeks. However your existing (never expires) access token will continue to work. Anyway check developers.facebook.com/docs/offline-access-deprecation – gremo