Facebook Connect in Php

Facebook Connect in Php
by

Facebook Connect in PHP,Just Follow these Steps :-

Upload all the files of zip folder on server.(Attached with this post)

Step 1 : Just open the file where you have to use facebook connect.(e.g abc.php)

Step 2: Just include this javascript file in head :-

“<script src=”http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php” type=”text/javascript”></script>”.

Step 3: Include the file “facebook.php”(Uploaded with this post).

Step 4: To put login button of facebook connect :-

<fb:login-button onlogin=’window.location=”http://www.xyz.com/abc.php”;’ size=”medium” background=”white” ></fb:login-button>

Step 5: create the object :-

$facebook = new Facebook(‘Facebook API key’,’Facebook App Secret Key’,true);

Step 6: To get the user id of facebook login person:-

“$fUserId = $facebook->get_loggedin_user();”

Step 7: To get the session key for the api ->

$fc = new FacebookRestClient(‘facebook Api keyApi secret key’,$facebook->api_client->session_key);

Step 8: To initiate facebook connect,put this facebook connect–>

<script type=”text/javascript”>

var fb_api_key = “Facebook API key”;

if (fb_api_key>””) FB.init(“Facebook API key”, “/xd_receiver.htm”);

</script>

Step 9: To get user data of the login person –>

if($fUserId) {

$fUserData = $fc->users_getInfo($fUserId, ‘last_name,first_name,sex,current_location’);

}

Step 10: To see the fetched data :

<?php if($fUserId)

{

?>

Firstname — <?php echo $fUserData[0][‘first_name’]; ?>

Lastname– <?php echo $fUserData[0][‘last_name’];?<

Sex– <?php echo $fUserData[0][‘sex’];?<

City– <?php echo $fUserData[0][‘current_location’][‘city’]; ?>

State–<?php echo $fUserData[0][‘current_location’][‘state’]; ?>

Country– <?php echo $fUserData[0][‘current_location’][‘country’]; ?>

Zip– <?php echo $fUserData[0][‘current_location’][‘zip’]; ?>

<?php } ?>

Step 11: To use the buttons(Login & Logout) if a person is login or not :

<?php if (!$fUserId) { ?>

<fb:login-button onlogin=’window.location=”http://www.xyz.com/abc.php”;’ size=”medium” background=”white” ></fb:login-button>

<?php }

else {

?>

<input type=”button” value=”Logout” onclick = ‘FB.Connect.logout(function() { document.location = “http://www.xyz.com/abc.php”; }); return false;’/>

<?php } ?>

Download : Facebook Files

It is done!


Recommended Posts

allAlgos IT Solutions | Web, Mobile, UX Design and IT Consulting Company