我使用 JavaScript 运行了一个非常基本的 FQL 查询,并不断返回错误对象{error_code: "2", error_msg: "Service temporarily unavailable", request_args: Array[8]}
我的目的是阅读comment_info.XID
最近通过 Facebook 发布到我的网站的评论(所有网站,不限于特定帖子)。
这是我的代码,主要基于 StackOverflow 上发布的一些示例:
<div id="fb-root"></div>
<div id="fbcomments"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
var fb_app_id = '*';
FB.init({
appId : fb_app_id,
session : null, // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
if (response.authResponse) {
var fb_access_token = response.authResponse.accessToken; // I even tried hard-coding the value from: https://graph.facebook.com/oauth/access_token?type=client_cred
FB.api(
{
method: 'fql.query',
query: 'SELECT xid,count FROM comments_info WHERE app_id="'+fb_app_id+'"',
access_token : fb_access_token
},
function(newresponse) {
$.each(newresponse, function(i, e) {
$("#fbcomments").append(""+e.text+""); // we get here, but e.text is undefined (see my error on top)
});
}
); //FB.api
} else { //response.authResponse
console.log('no response.authResponse');// do something...maybe show a login prompt
}
} else if (response.status === 'not_authorized') {
console.log(' not_authorized')
} else {
console.log('not_logged_in')
}
});
};
</script>
<script type="text/javascript"> (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true;js.src = "//connect.facebook.net/he_IL/all.js#appId=*&xfbml=1";d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script>
笔记:
- 我是使用 的应用程序的管理员
app_id
。 - 一旦我在当前任务中取得成功,我计划用一个匹配表
comments
来包装这个 FQL 查询,该表将返回实际的评论正文,而不仅仅是它的XID
. - 使用标准
graph.facebook
只会返回特定页面 url 的评论。我想要对我的网站发表的所有评论。 - 我不想 iFrame Facebook 评论审核工具。
我试过了:
- 使用和不使用
FB.init({'session'...}
- 硬编码
fb_access_token
。 #app_id=*
在<script src="">
值中使用和不使用。- 退出Facebook,登录等。
- 在运行此查询之间等待几天(甚至两周)。
更新:
我也使用了 PHP,但得到了同样的错误。这是我的 PHP 脚本:
// get user access_token
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
// response is of the format "access_token=AAAC..."
$access_token = substr(file_get_contents($token_url), 13);
$config = array(
'appId' => $app_id,
'secret' => $app_secret
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if ($user_id) {
$params = array(
'method' => 'fql.query',
'query' => "SELECT xid,count FROM comments_info WHERE app_id=$app_id",
'access_token' => $access_token
);
try {
$result = $facebook->api($params);
var_dump($result);
} catch (Exception $e) {
var_dump($e);
}
} else {
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
}
似乎没有任何效果。有什么想法有什么问题吗?