发送应用程序生成的通知时出错 [方法未实现,请求中的方法无效]
我正在尝试使用以下代码向我的应用程序用户发送应用程序生成的通知:
$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);
用户身份验证正常,我也获得了有效的访问令牌,但是当我调用时
$result = file_get_contents($apprequest_url);
我得到的响应是:
Method Not Implemented
Invalid method in request
任何想法可能会发生什么?如果我将 URL 放入浏览器中,它会正常工作并生成通知。
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在发送通知时发现了错误...这有点愚蠢,但问题是我试图在用于进行 API 调用的消息字符串中添加空格。
我的意思是,将“ ”替换为“%20”即可。我之前也尝试过对消息进行编码,但没有成功
,但它不起作用。所以我的解决方案是直接替换字符串中的空格,这不是一个优雅的解决方案。但我花了大约 10 个小时来处理这个问题,所以...
即
替换为:
我希望这对其他人有帮助,并且我花在进行一千次测试上的时间并没有浪费 xD
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