Derek
Derek

Reputation: 2112

Facebook php application - configure to request additional info

Summary:

How do I configure my facebook application to request additional information from the user.

The detail:

I decided recently to try to write a facebook application. The idea behind the graph api seemed a good one and I hoped it would be straightforward. Big mistake!

I've managed to cobble the following together which successfully retrieves the publicly available info about me:

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '*****',
  'secret' => '*****',
  'cookie' => true,
));

// Read session info from Facebook object above
$session = $facebook->getSession();

$me = null;
$myfriends = null;
$myalbums = null;
$myphotos = null;

// If logged in ok, load data into php objects for use in page
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me'); // infor about logged in person
    $myfriends = $facebook->api('/me/friends'); // list of their friends and associated ids
    $myphotos = $facebook->api('/me/photos'); // photos I've loaded or am tagged in -     requires permissions!
    $myalbums = $facebook->api('/me/albums');// Albums I've created - requires permissions!
} catch (FacebookApiException $e) {
    error_log($e);
  }
}

However, it can't get hold of my albums and photos because they require special permissions to be granted by the user. My problem is I can't see any settings in the facebook based application setup which would do this.

Can you help??

Upvotes: 0

Views: 619

Answers (2)

sashtinathan
sashtinathan

Reputation: 591

Well, The above answer is almost right. But if you are in need of other Graph API permissions, you can refer the following link Facebook_Permissions. And,the way to tweak the above code is : array('req_perms'=>'ADD THE REQUIRED PERMISSIONS', 'next'=>$returnUrl). Additionally, If there are more than one permission, separate them by a comma.

Upvotes: 1

Qiang
Qiang

Reputation: 61

Append the following code to yours. You need to set $url to be the URL of your facebook application, and adjust 'req_perms' based on your needs.

if(!$session) {
    $url = $facebook->getLoginUrl(array('req_perms'=>'email,publish_stream', 'next'=>$returnUrl));
    echo <<<EOD
<html>
<head>
<script type="text/javascript">function redirect(){ top.location.href = "$url"; }</script>
</head>
<body onload="redirect();">Please wait...</body>
</html>
EOD;
}

Upvotes: 1

Related Questions