動作する次のプラグインを挿入しました:
<fb:comments href="http://www.example.com/" width="580" num_posts="10"></fb:comments>
誰かがコメントを追加すると、このコメントは別のサイトの特定の投稿に投稿されます。このアクションでは、ユーザーに許可を求める必要があります。
誰かがコメントの挿入ボタンをクリックすると、イベント リスナーFB.Event.subscribe('comment.create' ...
が起動します。
次に、ユーザーが投稿の許可を与えていない場合、ポップアップが開き、他のページへの投稿の許可をユーザーに求めます。次に、挿入されたコメントがデータベースから取得されます (変数 comment_response のコールバックには、コメントのメッセージを含む変数がないため)。
問題は、コールバックの変数応答fql.query
が空であることです。また、タイムアウトで数秒待機しようとしました。
comment_response.commentID の出力を取得し、それを他のコールバックの外にハードコーディングして書き込み、ページを更新すると、結果が得られます。
また、コメントを照会する代わりに名前を取得するなどの単純な要求を行うと、結果も得られます。このコードの何が問題なのですか?
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
var post_id = 64564346456756;
var user_id = 12434566778788;
// init the FB JS SDK
FB.init({
appId : '75645367543465745', // App ID from the App Dashboard
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
//post comment
FB.Event.subscribe('comment.create', function(comment_response){
//console.log( comment_response );
//try to post on fanpage ... login
FB.login(function(login_response) {
//console.log(response);
// user is logged in and granted permissions.
if (login_response.authResponse) {
//get comment
//comment_response.commentID comment_response.href
//console.log( comment_response.commentID );
FB.api({
method: 'fql.query',
query: "SELECT text FROM comment WHERE post_fbid = '"+comment_response.commentID+"' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url='http://www.example.com/')",
access_token: login_response.accessToken
},
function( response ) {
//console.log( resp[0].text );
console.log(response);
});
}
else { // User cancelled login or did not fully authorize.
}
}, {scope:'publish_stream, read_stream'});
});
};
// Load the SDK's source Asynchronously
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/de_DE/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>
<fb:comments href="http://www.example.com/" width="580" num_posts="10"></fb:comments>