i’m trying to send app-generated notifications to my app users using the code:
$app_id = MY_APP_ID;
$app_secret = MY_APP_SECRET;
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $app_id .
"&client_secret=" . $app_secret .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
$user_id = SOME_USER_ID;
$apprequest_url ="https://graph.facebook.com/" .
$user_id .
"/apprequests?message='a message'" .
"&data='some_data'&" .
$app_access_token . "&method=post";
$result = file_get_contents($apprequest_url);
var_dump($result);
The user authentification is ok, also i’m getting a valid access token, but when i call
$result = file_get_contents($apprequest_url);
The response i get is:
Method Not Implemented
Invalid method in request
Any ideas what can be happening? If I put the url in a browser, it works fine and i generate the notification.
Thanks in advance
I found the error while sending notifications… It’s a bit silly but the problem was me trying to put white spaces in the message string I was using to make the API call.
I mean, it will work by replacing ‘ ‘ by ‘%20’. I also tried unssucessfully encoding the message previously with
But it didn’t work. So the solution for me was directly replacing spaces in my string, it’s not an ellegant solution. But i’ve spent like 10 hours dealing with this so…
I.e.
replaced by:
I hope this help someone else and the time i spent making a thousand tests was not wasted xD