Php &引用;请求此资源需要用户访问令牌。”;Facebook通知图表

Php &引用;请求此资源需要用户访问令牌。”;Facebook通知图表,php,facebook,facebook-graph-api,facebook-canvas,Php,Facebook,Facebook Graph Api,Facebook Canvas,注意:当用户接受我使用我的应用程序的权限时。我要求他们接受管理\u通知 我很困惑。我在网上对此进行了研究,似乎我收到了一些不推荐的和错误的信息,我正试图使用我的facebook画布应用程序通过facebook graph向用户发送通知。以下是我是如何做的,它不工作 public function getAccessToken() { $app_id = $this->settings['app_id']; $app_secrete = $this->settings[

注意:当用户接受我使用我的应用程序的权限时。我要求他们接受
管理\u通知

我很困惑。我在网上对此进行了研究,似乎我收到了一些不推荐的和错误的信息,我正试图使用我的facebook画布应用程序通过facebook graph向用户发送通知。以下是我是如何做的,它不工作

public function getAccessToken() {
    $app_id = $this->settings['app_id'];
    $app_secrete = $this->settings['app_secrete'];
    $url =  "https://graph.facebook.com/oauth/access_token?".
            "client_id={$app_id}".
            "&client_secret={$app_secrete}".
            "&grant_type=client_credentials";
    $c = curl_init($url);
    // necessary so CURL doesn't dump the results on your page
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($c);
    $result = explode("=", $result);
    curl_close ($c);
    return $result[1];
}
结果传递如下内容access_token=523216317ewwer235 | K4A1XugBpajwrweu1K2k12jzckdU。这就是我在代码中分解
=
符号的原因。每次用户进入我的应用程序时,我都会调用此函数。我获取访问代码并在下面的代码中将其作为
$token
传递

public function alertUser($userid,$token,$message="You have a notification") {
    $inviteMessage = $message;
    $inviteMessage = urlencode($inviteMessage);
    $url = "https://graph.facebook.com/{$userid}/notifications?access_token={$token}&".
    "template={$inviteMessage}&ref=notify";
    $c = curl_init($url);
    // necessary so CURL doesn't dump the results on your page
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($c);
    curl_close ($c);        
    $r = json_decode($result);
}
我得到以下回应

object(stdClass) {
    error => object(stdClass) {
        message => 'A user access token is required to request this resource.'
        type => 'OAuthException'
        code => (int) 102
    }
}

您必须使用POST请求才能使通知生效:

curl_setopt($c,CURLOPT_POST,true)


显然,您正在发出GET请求,试图请求资源

您必须使用POST请求才能使通知生效:

curl_setopt($c,CURLOPT_POST,true)


显然,您正在发出GET请求,试图请求资源

我想你可能是对的。我猜我也必须将参数设置为postData。我会尝试一下并更新帖子。因为我的代码在过去的一个小时里有很多变化。我想你可能是对的。我猜我也必须将参数设置为postData。我会尝试一下并更新帖子。因为我的代码在过去的一个小时里有很多变化。