This blog is for sharing technical knowledge based on open-source technology and many more Have fun coding !!!
Wednesday, 28 November 2012
Sunday, 25 November 2012
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)
Facebook Social
Login with Facebook Snippet
Javascript
function FBdoLogin() {
FB.init({appId: '2342321234423', status: true, cookie: true,
xfbml: true});
FB.login(function(response) {
if (response.authResponse) {
success:function(data)
{ //success page call the
});
}
},{scope: 'email,user_birthday,publish_stream'}); // getting permission from user
}
function startApp() {
var redirectUrl = path+'user/fbcheck';
window.top.location.href = redirectUrl;
}
UI
* include the facebook all.js in header
<script src="http://connect.facebook.net/en_US/all.js"></script>
<a class="fblogin" href="javascript:void(0);" onclick="FBdoLogin();return false;"><img src="localhost/images/connect-facebook-button.png">
Login with Facebook Snippet
Javascript
function FBdoLogin() {
FB.init({appId: '2342321234423', status: true, cookie: true,
xfbml: true});
FB.login(function(response) {
if (response.authResponse) {
success:function(data)
{ //success page call the
startApp();
}
});
}
},{scope: 'email,user_birthday,publish_stream'}); // getting permission from user
}
function startApp() {
var redirectUrl = path+'user/fbcheck';
window.top.location.href = redirectUrl;
}
UI
* include the facebook all.js in header
<script src="http://connect.facebook.net/en_US/all.js"></script>
<a class="fblogin" href="javascript:void(0);" onclick="FBdoLogin();return false;"><img src="localhost/images/connect-facebook-button.png">
Subscribe to:
Comments (Atom)