注意:当用户接受我使用我的应用程序的权限时。我请他们接受manage_notifications
我很困惑。我在网上研究这个,似乎我得到了不赞成和错误信息的混合,我试图使用脸谱图使用我的Facebook画布应用程序向用户发送通知。以下是我如何做到这一点而不起作用。
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
}
}
答案 0 :(得分:5)
您必须使用POST请求才能发送通知:
curl_setopt ($c, CURLOPT_POST, true);
显然你正在发出GET请求,试图请求资源。