Eric Eric - 1 year ago 117
PHP Question

Facebook scope PHP

I'm trying to work with Facebook's default PHP website integration and authentication.
When a user logs in, I'm able to request permissions to get various information from the user.

This question is kind of old. Please take note of harry33166's comment.

"If someone using Facebook SDK v4.4 is stumbling across this question, the answer by Dhiraj won't >work in that case as there is a small change. You don't have to include redirect_uri in the array >passed to getLoginUrl.

As per v4.4, getLoginUrl should work like:

$loginUrl = $facebook->getLoginUrl(
'scope' => 'email,user_checkins, user_birthday'

The various scopes can be found here: Facebook permissions."

It was really easy to figure out how to do it with the JavaScript one, but I'm confused where to specify the scope in the PHP example.

Basically, I just want to request for permission to access their email & location and maybe some other information.

Here is the code I'm working with:
(It's modified slightly, but it is almost an exact match to what they had.)

define('YOUR_APP_ID', '---------');
define('YOUR_APP_SECRET', '------------');

//Uses the PHP SDK. Download from
require 'facebook.php';

$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,

$FBUID = $facebook->getUser();

<?php if ($FBUID) {
$userInfo = $facebook->api('/' + $FBUID); ?>

<?php $FBName = $userInfo['name'];?>
Welcome <? // = $userInfo['name'] ?> -->

<?php } else { ?>
<div id="fb-root"></div>
<?php } ?>

window.fbAsyncInit = function() {
appId : '---------------',
status : true,
cookie : true,
xfbml : true,
oauth : true,

FB.Event.subscribe('auth.login', function(response) {

var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); = id; js.async = true;
js.src = "//";

Answer Source

This is how you typically specify scope in PHP (check the documentation):

$facebook = new Facebook(array(
    'appId'  => AppInfo::appID(),
    'secret' => AppInfo::appSecret(),

$loginUrl = $facebook->getLoginUrl(
        'scope'         => 'read_stream,publish_stream,publish_actions,manage_pages,email,user_checkins',
        'redirect_uri'  => $redirectURI

I hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download