facebook on apiwork

Today, I tried to combine with facebook and apiwork. Great!! it's not too hard. Now, I can call facebook class easily and apiwork can use [facebook developer wiki](http://wiki.developers.facebook.com/index.php/Main_Page). I just use Facebook Class for my apiwork.

In Controller (facebook.php)

<?php
class facebookController extends Controller {

function facebookController()
{
parent::Controller();
}

function index()
{
$this->load->Facebook();
$data[‘fb_user’]=$this->fb->get_loggedin_user();
$data[‘appapikey’]=AWConfig::fbapikey;
$data[‘fb’]=$this->fb;
$this->load->view("facebook_test",$data);
}
}
?>

In View (facebook_test.php),

<html>
<head>
<!– Call Javascript For FBML –>

<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US&quot; 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&quot;

//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&quot; )
–>

Logout
<?
}//End Facebook user
?>
</body>
</html>
comments powered byDisqus