简体   繁体   中英

Facebook PHP SDK get User Access Token

Hello I am a little confused and not sure what to do with the Facebook API.

So I set up a webhook for getting Graph API updates, when the user changes its name/email etc. It works perfectly, I am getting the json and I can see what fields have been changed.

But where to go now. I tried to get the accessToken with the userID and appID but I could not get it going. I was able to get the AppAccessToken but I cannot query the user data with that (only id and name) so i need the UserAccessToken.

How do I receive the actual changed data from the

$fb->get("/{userID}?fields=name,email")

Thank you for your help, there is so many things on web, I cannot really figure out what I need.

All best, Luke

$accessTokenEntity = new Facebook\Authentication\AccessToken();
$accessToken = $accessTokenEntity->getValue();

try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get('/me?fields=id,name',  $accessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

Didn't have chance to actually test it, but according to this it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM