Advertisement
ShawnsSpace

FB php detect expired access_token from error.

Dec 9th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require './src/facebook.php';
  4. $facebook = new Facebook(array(
  5.   'appId'  => 'YourAppId',
  6.   'secret' => 'YourAppSecret',
  7.   'cookie' => true, // enable optional cookie support
  8. ));
  9. try {
  10. $user = $facebook->getUser();
  11. } catch (FacebookApiException $e) {
  12. $user = null;
  13. }
  14. if($user){
  15. try {
  16. $me = $facebook->api('/me?fields=id,name,first_name,permissions');
  17. }catch (FacebookApiException $e){
  18. $thiserrorResult = $e->getResult();
  19.     if(isset($thiserrorResult[error][code]) && $thiserrorResult[error][code]=='2500' ){
  20.     // we need to reauth
  21.     $facebook->destroySession();
  22.     // do redirect here, or show login button
  23.     }          
  24. }
  25. }
  26. ?>
  27. <!DOCTYPE html>
  28. <html>
  29. <head><title></title></head>
  30. <body>
  31. Add javascript sdk here.
  32. </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement