我正在尝试使用代码发送应用程序生成的通知给我的应用程序用户:
$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放到浏览器中,它会正常工作,并生成通知。
Thanks in advance
在发送通知时发现错误…这有点傻,但问题是我试图在我用来进行API调用的消息字符串中放置空白。我的意思是,用"%20"代替"就可以了。我还尝试用
对消息进行编码,但没有成功。utf8_encode($message)
但它没有工作。所以我的解决方案是直接替换字符串中的空格,这不是一个优雅的解决方案。但是我已经花了10个小时来处理这件事了,所以……
。
"/apprequests?message='a message'" .
替换为:
"/apprequests?message='a%20message'" .
我希望这对其他人有帮助,我花了一千次测试的时间没有浪费xD