我可以在组/页面和用户墙上发帖,但我不希望我的应用程序在选定墙上发帖时显示错误,如果所选墙不允许发帖,那么有什么办法知道我们可以在目标墙上发帖吗?
注意:我发现了两个类似的问题,但它们与我想要的并不完全相关
1 应用程序可以在用户墙上发布
2 如何检查权限是否允许我在他的墙上发帖或不使用 php sdk
在采取任何负面行动之前,请在评论中讨论。
谢谢。
AFAIK,没有办法准确地检查你想要的方式,因为隐私各不相同,正如你已经说过的。唯一可以查询的隐私设置是组的OPEN, 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']))
.
此外,请查看表示组的 fql 表以获取更多信息(如果尚未查看)。
你的意思是如何检查用户是否允许在他们的墙上发帖吗?
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
我通过脸书获得了用户的上述权限。