简体   繁体   English

FB类按钮edge.create事件在登录后未触发

[英]FB like button edge.create event not firing after login

I have fb like button on my site, below is my code 我的网站上有fb like按钮,下面是我的代码

<fb:like  ref="bartastico_fblike" href="https://www.facebook.com/Wetechies" layout="button_count" action="like" show_faces="false" share="false"></fb:like>

window.fbAsyncInit = function() {
      console.log("init");
            FB.init({
                appId: 'xxxx', 
                status: true,
                cookie: true,
                oauth: true,
                xfbml: true
            });
   var page_like_or_unlike_callback = function(url, html_element) {
  console.log("page_like_or_unlike_callback");
  console.log(url);
  console.log(html_element);
};


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

  };


(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

the issue is edge.create is not firing when first time user clicks on like button and log in and Even I tried statuschange and authresponsechange events no event is getting fired for first time. 问题是edge.create不会在首次用户单击按钮并登录时触发,即使我尝试了statuschange和authresponsechange事件,也没有第一次触发任何事件。

But after that if I unlike and like the event fires properly. 但是在那之后,如果我与众不同并且喜欢该事件就可以正确触发。

Am using this inside php file within js script tag. 我在js脚本标签内的php文件中使用此文件。 I have changed my localhost to www.example.com so my siteurl is http://www.example.com and domain is www.example.com in app settings. 我已将本地主机更改为www.example.com,因此在应用程序设置中,我的siteurl为http://www.example.com ,域为www.example.com。

live example - http://jsfiddle.net/JY89q/ 实时示例-http://jsfiddle.net/JY89q/

clear your cache then click on the like button and login, like button doesn't turn to confirm in fiddle. 清除缓存,然后单击“赞”按钮并登录,“赞”按钮不会转动以确认。 repeat same thing couple of times - clean-like-login. 重复几次相同的事情-干净登录。 its not consistent it fires up once in a while. 它不一致,有时会触发。

Well, Nobody knows the answer except facebook. 好吧,除了facebook,没人知道答案。

Yes its a bug! 是的,它是一个错误! already reported but not been assigned by facebook to anybody to work on it yet. 已经报告,但尚未由facebook指派给任何人进行处理。

I have the same problem and didn't find an answer in months. 我有同样的问题,几个月都没找到答案。 I can give you a dirty workaround which works in desktop browsers sadly not on mobile: 我可以给您一个肮脏的解决方法,该方法可在台式机浏览器中使用,可惜不能在移动设备上使用:

You have to check for auth.login instead of edge.create. 您必须检查auth.login而不是edge.create。 Inside the auth.login callback call the edge.create action. 在auth.login回调内部,调用edge.create操作。 Inside the edge.create action you can now define your callback to redirect or do anything you like. 在edge.create动作中,您现在可以定义回调以重定向或执行您喜欢的任何事情。

//If not logged in
FB.Event.subscribe('auth.login', login_event);
//If already logged in just call edge.create
login_event();

//edge create event
var login_event = function(){
    FB.Event.subscribe('edge.create', page_like_callback);
}

var page_like_callback = function(){
    //Do your stuff
    location.href = url;
}

I know this is pretty dirty but like this my like-gate works fine on desktop browsers. 我知道这很脏,但是像这样,我的like-gate在桌面浏览器上可以正常工作。 The only problem is if the user is not logged in but already liked your page - you won't be able to catch this case sadly.. But I agree - edge.create not triggering if not logged in seems to be a bug imo as well. 唯一的问题是,如果用户未登录但已经喜欢您的页面,那么您将无法悲伤地捕获这种情况。.但是我同意-如果未登录,edge.create不触发似乎是一个错误,因为好。

Btw. 顺便说一句。 I'm using the auto init function instead of the FB.init().. 我使用的是自动初始化函数,而不是FB.init()。

js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appID=12321321321321&version=v2.0";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM