如何检查用户/应用程序是否可以在目标组墙上发布?

时间:2012-04-07 18:36:46

标签: php facebook facebook-graph-api

我可以在论坛/页面和用户墙上发帖,但我不希望我的应用在选定的墙上发布时显示错误,如果所选的墙不允许发布,那么有什么方法可以知道我们能够在目标墙上发布吗?

注意:我发现了两个类似的问题,但它们并不完全符合我的要求

1 Application able to post on user's Wall

2 How to check the permission whether a friend allow me to post on his wall or not using php sdk

在采取任何负面行动之前,请在评论中进行讨论。

感谢。

2 个答案:

答案 0 :(得分:1)

AFAIK,没有办法确切地检查你想要的方式,因为你已经说过,隐私会有所不同。可以查询的唯一隐私设置是groupOPEN, CLOSED, or SECRET,可以通过调用图表api来完成:

`http://graph.facebook.com/$Group_id`

返回包含字段privacy的json数据,该字段将是OPEN, CLOSED, or SECRET之一。

但最重要的是,您可以将组的设置限制为仅限组管理员。该权限无法检查

所以我认为你要做的就是检查返回的值,即发布后$response 。如果未给出权限,则返回的数据如下所示:

{
   "error": {
      "type": "Exception",
      "message": "You do not have permission to post in this group."
   }
}

因此,您可以检查$response是否有“错误”字段,并相应地通知用户。有点像这样:if(isset($response['error']))

如果还没有,请查看代表groups的fql表以获取更多信息。

答案 1 :(得分:1)

您的意思是如何检查用户是否已授权在墙上发布信息?

try {
    // Get the permissions this user has
    $call = $this->facebook->api("/me/permissions");

    // If they have the permission we require ('publish_stream')
    if($call['data'][0]['publish_actions']){
        try{
            // Do your magic here...
            // Also include your access token in the array
            $params = array('message'=> 'hello world');
            $call = $this->facebook->api('/me/feed','POST',$params);

        }catch(FacebookApiException $e) {
            $result = $e->getResult(); // prob no permissions
        }
    }
} catch(FacebookApiException $e) {
    $result = $e->getResult();
}

所以基本上,首先检查用户是否拥有特定操作的权限,然后检查$call[data][0]['publish_action']是否设置为1 (int)

$call = $this->facebook->api("/me/permissions");

的输出示例
[installed] => (int) 1
[email] => (int) 1
[publish_actions] => (int) 1

我通过facebook获得了用户的上述权限。