Skip to content

Instantly share code, notes, and snippets.

@phwd
Created October 17, 2012 12:23
Show Gist options
  • Save phwd/3905263 to your computer and use it in GitHub Desktop.
Save phwd/3905263 to your computer and use it in GitHub Desktop.
<?php
require '../src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
$attachment = array(
'message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://www.lycos.com',
'description' => 'Test de post depuis application PHP',
'picture' => 'http://www.lalibre.be/img/logoLaLibre.gif',
);
try {
$result = $facebook->api('/me/feed/','post',$attachment);
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$params = array(
'scope' => 'publish_actions',
'redirect_uri' => 'REDIRECT_URI'
);
$loginUrl = $facebook->getLoginUrl($params);
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
</head>
<body>
<h1>php-sdk</h1>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>
<h3>PHP Session</h3>
<pre><?php print_r($_SESSION); ?></pre>
<?php if ($user): ?>
<h3>Posted Feed (/me/feed)</h3>
<pre><?php print_r($result); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment