我试图找出是否已为用户授予'publish_action'权限(使用php)。
我可以查询图表,我只是坚持解析响应,以便能够获得publish_actions ='grant'。
查询是:
$ user_permissions = “https://graph.facebook.com/me/permissions?access_token=” 。$的access_token;
$ permissions = json_decode(file_get_contents($ user_permissions));
如果我打印回复
的print_r($权限);
我明白了......
stdClass对象([data] =>数组([0] => stdClass对象( [permission] =>安装[status] =>授予)[1] => stdClass对象 ([权限] => public_profile [status] =>已授予)[2] => stdClass的 对象([权限] => publish_actions [status] =>已授予)))
捕获致命错误:无法转换类stdClass的对象 字符串
基本上我只想在php中分配一个变量如果publish_actions [status] =='grant'
对此的任何帮助将不胜感激。
更新
尝试下面的Sahil建议:
$user_permissions = "https://graph.facebook.com/me/permissions?access_token=" .$access_token;
$permissions = json_decode(file_get_contents($user_permissions, TRUE));
$hasPublishPerm = false;
print_r($permissions['data']);
print_r($permissions);
foreach($permissions['data'] as $permission){
if($permission['permission']=="publish_actions" &&
$permission['status']=="granted"){
$hasPublishPerm = true;
break;
}
}
if($hasPublishPerm){
echo "User has granted the publish permission";
}
else{
echo "User has NOT granted the publish permission";
}
我收到此错误:
致命错误:不能将stdClass类型的对象用作...中的数组
答案 0 :(得分:0)
就这样做 -
$hasPublishPerm = false;
foreach($permissions['data'] as $permission){
if($permission['permission']=="publish_actions" &&
$permission['status']=="grantedd"){
$hasPublishPerm = true;
break;
}
}
if($hasPublishPerm){
echo "User has granted the publish permission";
}
else{
echo "User has NOT granted the publish permission";
}