NOTE: When the user accepts my permissions to use my app. I ask them to accept manage_notifications
I am so confused. I research this on the web and it seems I get a mix of deprecated and wrong information and I am trying to send a notification to the user using my facebook canvas app using facebook graph. the following is how I do it and its not working.
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];
}
The result passes something like this access_token=523216317ewwer235|K4A1XugBpajwrweu1K2k12jzckdU
. so that is why i explode the =
sign within the code. I call this function every time the user enters my app. I take the access code and pass it as $token
in the following code.
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);
}
and I get the following response
object(stdClass) {
error => object(stdClass) {
message => 'A user access token is required to request this resource.'
type => 'OAuthException'
code => (int) 102
}
}
You must use POST requests in order to make notifications work :
curl_setopt ($c, CURLOPT_POST, true);
Apparently you are making GET requests, trying to request a resource.
来源:https://stackoverflow.com/questions/14043512/a-user-access-token-is-required-to-request-this-resource-facebook-graph-for-n