Skip to content

Instantly share code, notes, and snippets.

@saturngod
Created March 5, 2010 07:29
Show Gist options
  • Save saturngod/322532 to your computer and use it in GitHub Desktop.
Save saturngod/322532 to your computer and use it in GitHub Desktop.
<?php
//download from http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz
//include_once 'fbconnect/config.php'; //has $api_key and $secret defined.
include_once 'facebook/facebook.php';
//global $api_key,$secret;
$appapikey = '';
$appsecret = '';
//Start Facebook
$fb=new Facebook($appapikey,$appsecret);
$fb_user=$fb->get_loggedin_user();
?>
<html>
<head>
<!-- Call Javascript For FBML -->
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script><script type="text/javascript">FB.init("<?= $appapikey ?>");</script>
<title>Facebook Connect</title>
</head>
<body>
<?php
if(!$fb_user)
{
?>
<!-- Login Button -->
<fb:login-button v="2" size="medium" onlogin="window.location.reload(true);">Connect with Facebook</fb:login-button>
<?php
}
else
{
echo "Facebook";
//User
//http://wiki.developers.facebook.com/index.php/Users.getInfo
//can retrive many user information except user's email , check wiki
$user_details=$fb->api_client->users_getInfo($fb_user, array('uid','last_name','first_name','proxied_email','email_hashes'));
$uid=$user_details[0]['uid'];
$firstName=$user_details[0]['first_name'];
$lastName=$user_details[0]['last_name'];
$proxemail=$user_details[0]['proxied_email'];
$email=$user_details[0]['email_hashes'];
echo $uid;
echo "<br>";
echo $email;
echo "<br>";
echo $proxemail;
echo "<br>";
echo $firstName;
echo "<br>";
echo $lastName;
//Friend
//http://wiki.developers.facebook.com/index.php/Friends.get
echo "<p>Friends:";
$friends = $fb->api_client->friends_get();
//slice the friend list
$friends = array_slice($friends, 0, 5);
foreach ($friends as $friend) {
echo "<br>$friend";
}
echo "</p>";
?>
<!--
http://developers.facebook.com/tools.php?connect_wizard
-->
<!-- Profile Picture -->
<fb:profile-pic uid="<?= $uid ?>" size="square" facebook-logo="true"></fb:profile-pic>
<br/>
<!-- Friend Pic -->
<div id="profile_pics"></div>
<script type="text/javascript">
var widget_div = document.getElementById("profile_pics");
FB.ensureInit(function () {
FB.Facebook.get_sessionState().waitUntilReady(function() {
FB.Facebook.apiClient.friends_get(null, function(result) {
var markup = "";
var num_friends = result ? Math.min(5, result.length) : 0;
if (num_friends > 0) {
for (var i=0; i<num_friends; i++) {
markup +=
'<fb:profile-pic size="square" uid="'+result[i]+'" facebook-logo="true"></fb:profile-pic>';
}
}
widget_div.innerHTML = markup;
FB.XFBML.Host.parseDomElement(widget_div);
});
});
});
</script>
<?
//status
$status=$fb->api_client->call_method("facebook.status.get", array('uid'=>$uid, 'limit'=>'5'));
for($i=0;$i<5;$i++)
{
echo $status[$i]['message'];
echo "<hr>";
}
//you can try
//print_r($status);
echo "<br>";
//Check Permission
$permission = $fb->api_client->Users_hasAppPermission('status_update');
if($permission)
{
//If permission have status update
$msg=$fb->api_client->call_method("facebook.status.set",array('status'=>'I can update stataus from fb connect'));
}
else
{
?>
<script>
/*
extended permission are
status_update, photo_upload, video_upload, create_note, and share_item
*/
//Call facebook and return to ornagai.com
//if not get permission , next for Allow, next_cancel for not Allow
location.href="http://www.facebook.com/authorize.php?api_key=<?= $appapikey ?>&v=1.0&ext_perm=status_update&next=http://www.yoursite.com/fbconnect.php&next_cancel=http://www.yoursite.com"
//You can also use dialog messagebox
/*
FB.Connect.showPermissionDialog("status_update", function(perms) {
if (!perms) {
continue_without_permission();
} else {
save_session();
}
});
*/
</script>
<?
}
?>
<!--
with PHP
$fb->logout( "http://site.com/returnAfterLogout.php" )
-->
<a href="javascript:FB.Connect.logout()" >Logout</a>
<?
}//End Facebook user
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment