3

我插入了以下有效的插件:

<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>
4

0 回答 0