Skip to content

Instantly share code, notes, and snippets.

@jeremygibbs
Created March 19, 2012 14:36
Show Gist options
  • Save jeremygibbs/2114528 to your computer and use it in GitHub Desktop.
Save jeremygibbs/2114528 to your computer and use it in GitHub Desktop.
Obtain Long-Term Authorization Token From Facebook For Offline Posting
<?php
//-- Facebook API --//
//-- https://github.com/facebook/facebook-php-sdk --//
require_once 'facebook-php-sdk/src/facebook.php';
//-- App Information --//
$app_id = 'YOUR APP ID';
$app_secret = 'YOUR APP SECRET';
// Create Facebook Instance
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
//-- To Facebook (Notice we ask for offline access) --//
if (empty($_REQUEST))
{
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'scope' => 'offline_access,publish_stream'
));
header('Location:'.$loginUrl );
}
//-- From Facebook --//
else
{
$user = $facebook->getUser();
if($user)
{
$access_token = $facebook->getAccessToken();
echo "Your access token is: <br><br>$access_token";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment