我正在尝试使用以下代码向应用用户发送应用生成的通知:
$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
任何想法可以发生什么?如果我将网址放在浏览器中,它可以正常工作,我会生成通知。
提前致谢
答案 0 :(得分:0)
我在发送通知时发现错误...这有点傻但问题是我试图在我用来进行API调用的消息字符串中放置空格。 我的意思是,它可以通过''替换'%20'来实现。我还尝试使用
对以前的消息进行不必要的编码utf8_encode($message)
但它没有用。所以我的解决方案是直接替换我的字符串中的空格,这不是一个优雅的解决方案。但我花了10个小时处理这个问题......
即
"/apprequests?message='a message'" .
替换为:
"/apprequests?message='a%20message'" .
我希望这可以帮助别人,而且我花了一千次测试的时间并没有浪费xD