本文介绍了使用PHP检查特定的Facebook用户权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ request = new FacebookRequest($ session,'GET ','/ me / permissions');
$ response = $ request-> execute();
$ graphObject = $ response-> getGraphObject() - > asArray();
我可以输入:
echo print_r($ graphObject,1);
以获取所有权限的打印,但是我想检查特定权限是否被授予(在我的情况下是publish_actions),并采取行动。如何提取此对象的元素以在PHP中执行if测试?
解决方案
获取原始响应并使用json_decode
$ publish_actions_perm ='';
$ array = json_decode($ response-> getRawResponse(),true);
foreach($ array ['data'] as $ perm){
if($ perm ['permission'] =='publish_actions'){
$ publish_actions_perm = $ perm ['status ]; //授予
break;
}
}
I have the following code to get a users Facebook permissions:
$request = new FacebookRequest( $session, 'GET', '/me/permissions' );
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
I can type:
echo print_r( $graphObject, 1 );
to get a print out of all the permissions BUT I want to check whether or not a particular permission has been granted (in my case 'publish_actions') and act on it. How do I extract this element of the object to perform an 'if' test in PHP?
解决方案
Get the raw response and use json_decode
$publish_actions_perm = '';
$array = json_decode($response->getRawResponse(), true);
foreach($array['data'] as $perm){
if($perm['permission']=='publish_actions'){
$publish_actions_perm = $perm['status']; //granted
break;
}
}
这篇关于使用PHP检查特定的Facebook用户权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!