How do I ask for facebook permissions in PHP? can you please give me an example?
thanks.
It seems that you are new to the Facebook API, I suggest you the following:
To ask for permissions, you can do the following:
<fb:login-button scope="read_stream"></fb:login-button>
More about this can be found in this answer too.
You can test all of the above locally, and here's a tutorial that I wrote about how to do it.
Assuming you have the user's access_token
(which you can get via $facebook->getAccessToken()
after you've logged a user in:
try{
$permissions = $facebook->api('/me/permissions', 'get', array('access_token'=>$access_token));
print_r($permissions, true);
if(empty($permissions['data'][0]['installed'])){
echo 'User has not installed the application.';
}
if(empty($permissions['data'][0]['publish_stream'])){
echo 'User does not have the publish_stream permission.';
}
}catch(Exception $e){
echo $e->getMessage();
}
This is how you request permissions.. To detect if a user is authorized with your app or not, etc you have to use the Facebook PHP library, that is much more complicated, read here to get started: http://developers.facebook.com/docs/
Just for requesting permission you first need to have your fb-root div and include the Facebook Javascript Graph API file, then put a login button.. The autologoutlink parameter specifies if it should show "Logout" if the user is already connected to your application.
The perms is the permissions requested for the app, a full list is on the Facebook developer docs site.. You have to enter your application ID also.
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<fb:login-button autologoutlink="true" perms="email,user_birthday" size="large" onlogin="window.location = '/';">Connect to this application using Facebook</fb:login-button>
</div>
<script>
FB.init({appId: 'ENTER YOUR APPLICATION ID HERE', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>