I am trying to get PAGE ACCESS TOKEN using facebook USER ACCESS TOKEN The Steps I have completed are
My Application path = http://localhost/facebook_req/
- On my index.php I have successfully allowed my admin user to use the app using the below permissions
<?php session_start(); include('Facebook/autoload.php'); $fb = new Facebook\Facebook(array('app_id' => '{appid}', 'app_secret' => '{appsecret}', 'default_graph_version' => 'v2.7')); $helper = $fb->getRedirectLoginHelper(); $permissions = array('publish_pages','manage_pages','pages_show_list'); $loginUrl = $helper->getLoginUrl('http://localhost/facebook_req/callback.php', $permissions); echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
2 When I click the log in with facebook I get the dialog and I allow as the I allow the app which I created on the callback.php file I used the getRedirectLoginHelper(), retrieved/got the USER ACCESS TOKEN printed the user access token & token metadata and finally tried to post to user account and it was successful (see below sample var_dump of my token metadata)
<code>
$_SESSION['fb_access_token'] = $accessToken->getValue();
D:\wamp64\www\facebook_req\callback.php:48:
object(Facebook\Authentication\AccessTokenMetadata)[13]
protected 'metadata' =>
array (size=7)
'app_id' => string 'xxxxxxxxxxxxxxx' (length=15)
'application' => string 'xxxxxxxxxxx' (length=8)
'expires_at' =>
object(DateTime)[17]
public 'date' => string '2016-11-03 11:35:38.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
'is_valid' => boolean true
'issued_at' =>
object(DateTime)[18]
public 'date' => string '2016-09-04 11:35:38.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
'scopes' =>
array (size=5)
0 => string 'manage_pages' (length=12)
1 => string 'publish_pages' (length=13)
2 => string 'pages_show_list' (length=15)
3 => string 'publish_actions' (length=15)
4 => string 'public_profile' (length=14)
'user_id' => string 'xxxxxxxxxxxxxxxx' (length=15)
</code>
- This part is where it gets weird because I cant seem to get the PAGE ACCESS TOKEN when I tried to get the page access token using graph explorer it works but it doesnt work on my code
ACCESS TOKEN - user access token received from step 2 callback.php file METHOD - GET FIELDS - nonupublic?fields=access_token This works on graph explorer
My php code returns USER ACCESS TOKEN instead of PAGE ACCESS TOKEN
<code>
$fb = new Facebook\Facebook(....);
$requestx = $fb->request('GET', '/nonupublic?fields=access_token',array(),$_SESSION['fb_access_token']);
var_dump($_SESSION['fb_access_token']);
var_dump($requestx);
</code>
the issue is var_dump($_SESSION['fb_access_token']); and var_dump($requestx); are identical they aren't different and I cant seem to post to facebook page
by the way im following the guide on the document url - https://developers.facebook.com/docs/pages/access-tokens
could anyone please advice