简体   繁体   English

如何获得Graph Api For PHP facebook SDK的万岁访问令牌?

[英]How to get Long live access token for Graph Api For PHP facebook SDK?

I have tried to following way 我试过按照方式 在此输入图像描述

but i got Error "The access token does not belong to application " i have checked lot of time in my app id and secrt id, app id is correct but This error shown again and again I didn't peridict this Error? 但我得到错误“访问令牌不属于应用程序”我已经检查了很多时间在我的应用程序ID和secrt ID,应用程序ID是正确但这个错误一次又一次显示我没有peridict这个错误? and also i have tried following way also 而且我也尝试过以下方式

https://graph.facebook.com/v2.2/oauth/access_token?grant_type=fb_exchange_token&client_id=CLIENT_ID &client_secret=SECRED CODE&fb_exchange_token=EAACEdEose0cBAJRZCZBIaDmW3oOO6SHaOkQLKdgyjp1evGoQ19mYcZCXu5wWLwZABJUbV77tjPjiE2pac2fDEmjM1tZAZB8hflSyERXFWIZB2DtzZAGSgVX6Ukb0ZAZAzd6pohnZBXU0T2aqYwf1umUxsfgHQXBNmM15yhdZBG2Br https://graph.facebook.com/v2.2/oauth/access_token?grant_type=fb_exchange_token&client_id=CLIENT_ID &client_secret = SECRED CODE&fb_exchange_token = EAACEdEose0cBAJRZCZBIaDmW3oOO6SHaOkQLKdgyjp1evGoQ19mYcZCXu5wWLwZABJUbV77tjPjiE2pac2fDEmjM1tZAZB8hflSyERXFWIZB2DtzZAGSgVX6Ukb0ZAZAzd6pohnZBXU0T2aqYwf1umUxsfgHQXBNmM15yhdZBG2Br

PHPsdk 5 and v2.8 PHPsdk 5和v2.8

$fb = new Facebook\Facebook([
  'app_id'                => 'xxxxxxxxx',
  'app_secret'            => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'default_graph_version' => 'v2.8',
]);

$helper = $fb->getRedirectLoginHelper();
try {

  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // There was an error communicating with Graph
  echo $e->getMessage();
  exit;
}

$client = $fb->getOAuth2Client();
try {
  // Returns a long-lived access token
  $accessTokenLong = $client->getLongLivedAccessToken($accessToken);
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // There was an error communicating with Graph
  echo $e->getMessage();
  exit;
}

if (isset($accessTokenLong)) {
  // Logged in.
  $_SESSION['facebook_access_token'] = (string) $accessTokenLong;
}

Reference url : https://www.sammyk.me/upgrading-the-facebook-php-sdk-from-v4-to-v5 参考网址: https//www.sammyk.me/upgrading-the-facebook-php-sdk-from-v4-to-v5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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