使用通知API需要什么权限?

时间:2019-08-24 21:07:32

标签: php facebook-graph-api notifications

我需要获得什么权限才能使用Notifications API?我的测试应用包含两个文件:

nfytest.php:

<?php
require_once "../vendor/facebook/graph-sdk/src/Facebook/autoload.php";
session_start(); $_SESSION = array();

echo "<html><body>";

try{
    $fb = new Facebook\Facebook(['app_id' => 'xxx','app_secret' => 'xxx', 'default_graph_version' => 'v3.2']);
    $helper = $fb->getRedirectLoginHelper();
    $loginurl = $helper->getLoginUrl("https://www.bkassist.com/dnamatchmakerdev/callback.php",  'email', 'publish_to_groups']);
    echo "<a href='$loginurl'>Pleaseclick on this link</a>";
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    error_log($e->getMessage());
    echo 'Graph returned an error: '. $e->getMessage();
}catch(Facebook\Exceptions\FacebookSDKException$e){
    error_log($e->getMessage());
    echo 'Facebook SDK returned anerror: ' . $e->getMessage();
}
echo "</body></html>"; return 200;

?>

callback.php:

<?php
require_once "../vendor/facebook/graph-sdk/src/Facebook/autoload.php";
session_start();

ini_set("error_log", "error.log");

echo "<html><body>";

try
    {
    $fb = new Facebook\Facebook(['app_id' => 'xxx', 'app_secret' => 'xxx', 'default_graph_version' => 'v3.2']);
    $helper = $fb->getRedirectLoginHelper();
    $at = $helper->getAccessToken();
    $fb->post("/2465651860/notifications",  ["template" => "@[2465651860] has posted something you said you were interested in", "href " => "index?nfycallback"], $at);
    echo "Success. Or at least not failure.";
    }
catch(Facebook\Exceptions\FacebookResponseException $e) 
    {
    error_log($e->getMessage());
    echo 'Graph returned an error: ' . $e->getMessage();
    } 
catch(Facebook\Exceptions\FacebookSDKException $e) 
    {
    error_log($e->getMessage());
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    }

echo "</body>/</html>";
return 200;
?>

运行此命令将产生错误:图形返回错误:不支持的发布请求。 ID为'2465651860'的对象不存在,由于缺少权限而无法加载或不支持此操作。请阅读https://developers.facebook.com/docs/graph-api/

上的Graph API文档

我已经做了,但是还没有找到启示。 [对不起代码的格式-我发誓我试图让它看起来不错!]

1 个答案:

答案 0 :(得分:0)

首先,我认为您不应在问题中粘贴您的应用信息。因此,请更改密码以保护您的应用。

然后,我做了一些测试,仅不给出access_token参数将返回此错误。那么检查访问令牌参数吗?

顺便说一句,必须使用应用程序access_token调用此方法。并且只能发送安装您的应用程序的通知。

相关问题