Retriving data from facebook snippet
reference : https://developers.facebook.com/docs/guides/canvas
note: create your own app in fb you will get appId and secret key
download here: https://github.com/facebook/facebook-php-sdk/blob/master/src/facebook.php
https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php
require 'facebook.php'; // add this in your library and call it where u want to require
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '2541542541254', //example appid
'secret' => 'b9d6e03597d288e5605dd8060ed75be', //example secret key
));
// Get User ID
echo $user = $facebook->getUser();
if ($user) { // Proceed knowing you have a logged in user who's authenticated.
try {
$user_profile = $facebook->api('/me');
$user_friends = $facebook->api('/me/friends?fields=name');
$user_interest = $facebook->api('/me?fields=interests');
$user_permissions = $facebook->api('/me/permissions');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
print_r($user_profile); // we will get all the basic information from facebook,such as education,address,work etc.(according to the scope we will get the info from fb)
reference : https://developers.facebook.com/docs/guides/canvas
note: create your own app in fb you will get appId and secret key
download here: https://github.com/facebook/facebook-php-sdk/blob/master/src/facebook.php
https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php
require 'facebook.php'; // add this in your library and call it where u want to require
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '2541542541254', //example appid
'secret' => 'b9d6e03597d288e5605dd8060ed75be', //example secret key
));
// Get User ID
echo $user = $facebook->getUser();
if ($user) { // Proceed knowing you have a logged in user who's authenticated.
try {
$user_profile = $facebook->api('/me');
$user_friends = $facebook->api('/me/friends?fields=name');
$user_interest = $facebook->api('/me?fields=interests');
$user_permissions = $facebook->api('/me/permissions');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
print_r($user_profile); // we will get all the basic information from facebook,such as education,address,work etc.(according to the scope we will get the info from fb)
No comments:
Post a Comment