我试图从开发者网页测试示例
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . facebook::getConfig( 'appId' ) .
"&client_secret=" . facebook::getConfig( 'secret' ) .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
$user_id = "100002758712176";
$apprequest_url = "https://graph.facebook.com/".
$user_id .
"/apprequests?message='test string'&" .
$app_access_token . "&method=post";
$result = file_get_contents(urlencode($apprequest_url));
echo "App Request sent? ". $result;
并得到了eror [function.file-get-contents]:无法打开流:HTTP请求失败! HTTP / 1.1 400错误请求 当我在浏览器中使用$ apprequest_url时都可以。问题在哪里?
答案 0 :(得分:0)
首先,您应该在url中对您发送的字符串进行urlencode:
$apprequest_url = "https://graph.facebook.com/" . $user_id . "/apprequests?message=" . urlencode('test string') . "&" . $app_access_token . "&method=post";
答案 1 :(得分:0)
有些东西看起来很奇怪......
$result = file_get_contents(urlencode($apprequest_url));
首先,看起来你正在编码整个网址。其次,你的url字符串包含$ app_access_token,但它没有绑定到param键...可能只想尝试编码“message”的URL并在你的url stirng中添加“access_token”:
$message = urlencode('test string');
$apprequest_url = "https://graph.facebook.com/$user_id/apprequests?";
$apprequest_url .= "message=$message&access_token=$app_access_token&method=post";