如果人们使用类似按钮,则无法捕获

时间:2014-06-23 18:59:01

标签: javascript html fbconnect

如果一个人按下了类似的按钮,我尝试了许多不同的捕捉方式,但我似乎无法抓住点击。

这是HTM:

<fb:login-button autologoutlink="true"></fb:login-button>
<div id="alertClick" class="fb-like" data-href="https://www.facebook.com/ProbandoRest" data-layout="standard" data-action="like" data-show-faces="true" data-share="false"></div>
<div class="fb-share-button" data-href="https://www.facebook.com/ProbandoRest" data-type="button_count"></div>
<div id="fb-root"></div>
<div
  class="fb-comments"
  data-href="https://www.facebook.com/ProbandoRest"
  data-numposts="5"
  data-colorscheme="light">
</div>

这是JS:

<script>
(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=699580430058671&version=v2.0";
    fjs.parentNode.insertBefore(js, fjs);
    console.log("comment_callback");
} (document, 'script', 'facebook-jssdk'));

$(document).ready(function () {
    console.log("comment_callback");
    FB.Event.subscribe('edge.create', page_like_or_unlike_callback);
    FB.Event.subscribe('edge.remove', page_like_or_unlike_callback);
    FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback);
    FB.Event.subscribe('auth.statusChange', auth_status_change_callback);
});

$("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });

$("#alertClick").click(function () {
    alert('Aqui se cuenta los shares que se hayan dado por usuario');
    console.log("alert click aqui");
});

FB.api('/me/likes/642246055864172', { limit: 1 }, function (r) {
    if (r.data.length == 1) {
        alert('ya le gustaba al usuario');
    } else {
        alert('Todavia no le gusta al usuario');
    }
});

window.fbAsyncInit = function () {
    FB.init({
        appId: '642246055864172',
        status: false,
        cookie: false,
        xfbml: true
    });

    //Additional
    FB.Event.subscribe('edge.create',
                    function (response) {
                        alert('LIKED: ' + response);
                        console.log("comment_callback");
                    }
             );
};

var comment_callback = function (response) {
    console.log("comment_callback");
    console.log(response);
    alert('Hola regreso el comment');
}

var page_like_or_unlike_callback = function (url, html_element) {
    console.log("page_like_or_unlike_callback");
    console.log(url);
    console.log(html_element);
    alert('Hola regreso el comment');
}
var auth_response_change_callback = function (response) {
    console.log("auth_response_change_callback");
    console.log(response);
}

var auth_status_change_callback = function (response) {
    console.log("auth_status_change_callback: " + response.status);
}

我尝试了我在FB Connect文档中看到的各种方式。堆栈溢出处的其他一些答案。我使用C#在visual studio中编程,我在FireFox浏览器中遇到的错误是:

ReferenceError: FB is not defined Info:44
Use of getAttributeNode() is deprecated. Use getAttribute() instead. 8C1Yby4wT_P.js:148
Empty string passed to getElementById().

我无法找到为什么当我点击按钮时它没有捕捉到。我发现fb没有定义是因为在我的应用程序中我仍然没有设置user_likes属性,但我不确定。

1 个答案:

答案 0 :(得分:1)

好的,谢谢我 - 我把所有东西放到fbAsyncInit和外面的函数中。这是代码:

window.fbAsyncInit = function () {

    FB.Event.subscribe('edge.create', page_like_or_unlike_callback);

    FB.Event.subscribe('edge.remove', page_like_or_unlike_callback);

    FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback);

    FB.Event.subscribe('auth.statusChange', auth_status_change_callback);

    FB.Event.subscribe('comment.create', comment_callback);

    FB.Event.subscribe('comment.remove', comment_callback);

};

var comment_callback = function (response) {
    console.log("comment_callback");
    console.log(response);
    alert('Hola regreso el comment');
}

var page_like_or_unlike_callback = function (url, html_element) {
    console.log("page_like_or_unlike_callback");
    console.log(url);
    console.log(html_element);
    alert('Hola Like o dejo de likear algo');
}
var auth_response_change_callback = function (response) {
    console.log("auth_response_change_callback");
    console.log(response);
}

var auth_status_change_callback = function (response) {
    console.log("auth_status_change_callback: " + response.status);
}

这解决了我的问题。我离开了函数(d,s,id),取出了剩下的部分。不,我将继续在window.fbAsyncInit

中添加我需要捕获的内容