我正在通过我的开发者测试帐户开发一个应用程序,我所做的只是尝试向我的用户发布测试通知。我正在使用 facebook requests 2.0 文档执行此操作,因此我的代码如下所示:
$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 = $this->user->id;
$apprequest_url ="https://graph.facebook.com/" .
$user_id .
"/apprequests?message='testing notification'" .
"&" .
$app_access_token . "&method=post";
$result = file_get_contents($apprequest_url);
echo "Request id number: " . $result;
当我这样做时,我在页面上收到一条错误消息,提示“无法打开流”,但是当我将 url 复制并粘贴到地址栏时,我没有收到任何错误消息,并返回了一个请求 ID。有人知道为什么会这样吗?
最佳答案
我使用 curl 而不是 file_get_contents
解决了这个问题。 file_get_contents
用于出于某种原因抛出错误。
curl 的 cpde 是:
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL, $apprequest_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$result = curl_exec($ch);
curl_close($ch);
我知道我来晚了,但我希望它能帮助到别人。
关于php - Facebook Requests 2.0 Error #200 param ids 中的所有用户必须接受 TOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6454597/