Reputation: 129
I am trying to check the permissions that users have allowed for my site and am using the facebook SDK to get the permissions in an array.
array(1) {
["data"]=> array(3) {
[0]=> array(2) {
["permission"]=> string(9) "installed"
["status"]=> string(7) "granted" }
[1]=> array(2) {
["permission"]=> string(14) "public_profile"
["status"]=> string(7) "granted" }
[2]=> array(2) {
["permission"]=> string(15) "publish_actions"
["status"]=> string(7) "granted" } } }
i have found some code to search the array to find a specific permission, however I think the SDK has changed since this code was written.
if( array_key_exists('publish_actions', $permissions['data'][0]) ) {
// Permission is granted!
// Do the related task
$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
} else {
// We don't have the permission
// Alert the user or ask for the permission!
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
}
i'm looking for a way to search for publish_actions
and identify whether it is declined
or granted
.
Upvotes: 1
Views: 294
Reputation: 1118
You just have to convert the permission['data']
array in a more usuable array ...
$arr = array();
foreach( $permissions['data'] as $v){
$arr[$v['permission']] = $v['status'];
}
var_dump($arr);
Then use your script a bit modified :
if( array_key_exists('publish_actions', $arr) && $arr['publish_actions'] == 'granted' ) {
// Permission is granted!
// Do the related task
$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
} else {
// We don't have the permission
// Alert the user or ask for the permission!
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
hope this is what you asked ... have fun
Upvotes: 1