Created
January 17, 2012 20:32
-
-
Save jaredhabeck/1628718 to your computer and use it in GitHub Desktop.
Facebook PHP SDK - check access token validity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this follows the assumption that you've already instantiated the facebook SDK | |
// e.g. $facebook = new Facebook(); | |
// The key is the first api() call - you need to try to access something which requires the access token | |
// you are attempting to validate. | |
// e.g. if your access token has *no* special permissions you could use $facebook->api('/me'), | |
// which is the most basic permission level. | |
try { | |
$facebook->api('/me'); | |
} catch (Exception $e) { | |
if ($e->getType() == "OAuthException") { | |
$url = $this->facebook->getLoginUrl(array( | |
'redirect_uri' => "<your redirect uri which has to be set as owned by the app>" | |
)); | |
echo "<script type='text/javascript'>top.location.href = '$url';</script>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment