1

注意:当用户接受我使用我的应用程序的权限时。我要求他们接受manage_notifications

我感到很困惑。我在网上对此进行了研究,似乎我得到了已弃用和错误信息的混合,我正在尝试使用我的 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
    }
}
4

1 回答 1

5

您必须使用 POST 请求才能使通知起作用:

curl_setopt ($c, CURLOPT_POST, true);

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

于 2012-12-26T18:50:06.673 回答