Skip to content

Instantly share code, notes, and snippets.

@brunoamaral
Created October 9, 2012 06:19
Show Gist options
  • Save brunoamaral/3856956 to your computer and use it in GitHub Desktop.
Save brunoamaral/3856956 to your computer and use it in GitHub Desktop.
Facebook SDK example : saving user data to file
<?php
function facebooklog(){
require('/PATH_TO_FACEBOOK_PHP_SDK/src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$url = $_SERVER['REQUEST_URI'];
$file = 'b_facebook.txt';
$current = file_get_contents($file);
$current .= date(r) . ";" . $user_profile[name] . ";" . $url . "\n";
file_put_contents($file, $current);
} catch (FacebookApiException $e) {
$user = null;
}
} else {
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment