我目前正在将较旧的 Facebook 应用程序更新到 Facebook PHP SDK 4.0 版。该应用程序只是将消息发布到用户的墙上,从而请求用户的publish_actions权限。由于该应用尚未提交应用审核,我正在使用一个开发者帐户和一个测试用户帐户进行测试。
当我登录测试用户帐户并打开应用程序时,应用程序会检查是否已授予publish_actions权限。在我的场景中,这对测试用户来说很好:
FacebookSession::setDefaultApplication($config['appId'], $config['secret']);
$helper = new FacebookCanvasLoginHelper();
try {
$session = $helper->getSession();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
} catch(\Exception $ex) {
// When validation fails or other local issues
}
if($session) { //When app installed
$request_perm = new FacebookRequest($session, 'GET', '/me/permissions');
$response_perm = $request_perm->execute();
$graphObjectPermissions = $response_perm->getGraphObject()->asArray();
$permissions = [];
foreach ($graphObjectPermissions as $key => $permObject) {
$permissions[$permObject->permission] = $permObject->status;
}
if(array_key_exists('publish_actions', $permissions) && $permissions['publish_actions']=='granted'){
echo "Permission granted!";
}
但是,当我登录开发者帐户并使用GET user_id/permissions查询测试用户的权限时,返回的 graphObject 根本不包含权限publish_actions(仅电子邮件和公共配置文件)。
array ( 'email' => 'granted', 'public_profile' => 'granted', )
这是请求的代码,$access_token 包含我的应用的应用访问令牌。
$thisSession = new FacebookSession($access_token);
$request_perm = new FacebookRequest($thisSession, 'GET', '/' . $data['user_id'] . '/permissions');
$response_perm = $request_perm->execute();
$graphObjectPermissions = $response_perm->getGraphObject()->asArray();
$permissions = [];//create permissions array
foreach ($graphObjectPermissions as $key => $permObject) {
$permissions[$permObject->permission] = $permObject->status;
}
var_export($permissions);
为了使用 GET user_id/permissions 从开发者帐户检查 publish_actions 权限,我需要更改/做什么?