Easy Way to Check User’s Permission, Using Rest Api in Graph Api and Getting Facebook App Friend With Fql

It was very easy to get app friends using Facebook’s legacy rest api. It is still easy to get app friends with graph api. The very good side og the graph api is that you can call the rest api with in graph api. In this post i will show you use rest api in grpah api and using fql we will get the app friends.

Let’s first define our variables and login. Here i am also checking for permission – does the app has permission from the user or not.

 define("FACEBOOK_APP_ID", 'app id');
define("FACEBOOK_API_KEY", 'app key');
define("FACEBOOK_SECRET_KEY", 'secret key');
define("FACEBOOK_CANVAS_URL", 'http://apps.facebook.com/your-app/');
define("SITE_URL", 'site url');

$facebook = new Facebook(array(
  'appId'  => FACEBOOK_APP_ID,
  'secret' => FACEBOOK_SECRET_KEY,
  'cookie' => true,
));

$session = $facebook->getSession();

$loginUrl = $facebook->getLoginUrl(
	array(
		'canvas'=> 1,
		'fbconnect' => 0,
		'req_perms' => 'manage_pages,offline_access,user_likes,read_stream'		
	)
);

$me = null;
$chk=0;
if ($session) {
	try {
		$uid = $facebook->getUser();
		$me = $facebook->api('/me');
		$permissions = $facebook->api('/me/permissions');
		if(count($permissions['data'][0])<5)
			$chk=1;

	} catch (FacebookApiException $e) {
		//error_log($e);
	}
}
if (!$me or $chk==1) {
	echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}

now let call the rest api to get app friends

$app_friends = $facebook->api(array(
     'method' => 'friends.getAppUsers',
      'callback' => ''
));

Now we get app friends using fql

$fql = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 ={$uid}) AND is_app_user =1";	
$param  =   array(
       'method'    => 'fql.query',
       'access_token' => $facebook->getAccessToken(),
       'query'     => $fql,
       'callback'  => ''
);
$app_friends  =   $facebook->api($param);

Pretty easy huh?

About Zakir Hyder

This entry was written by .

09. June 2011 by Zakir Hyder
Categories: Facebook, Graph Api, PHP, Social Networking Application Development | Tags: , , , | Comments

Comments

  1. […] Easy Way to Checking User’s Permission, Using Rest Api in Graph Api and Getting Facebook App F… Friday, June 10, 2011 5:52 AM It was very easy to get app friends using Facebook’s legacy rest api. It is still easy to get app friends with graph api. The very good side og the graph api is that you can call the rest api with in graph api. In this post i will show you use rest api in […] […]