FB像按钮edge.create事件登录后不触发 [英] FB like button edge.create event not firing after login

查看:948
本文介绍了FB像按钮edge.create事件登录后不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有fb like按钮,下面是我的代码

I have fb like button on my site, below is my code

<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'));

问题是edge.create在第一次用户点击按钮并登录时不会触发,即使我尝试了statuschange和authresponsechange事件,没有事件首次被触发。

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.

但是之后,如果我不同,喜欢事件​​正常触发。

But after that if I unlike and like the event fires properly.

在js脚本标签内使用这个php文件。
我已将本地主机更改为www.example.com,因此我的siteurl是 http://www.example.com ,域是www.example.com在应用程序设置。

Am using this inside php file within js script tag. 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.

现场示例 - 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.

推荐答案

我有同样的问题,在几个月内没有找到答案。我可以给你一个肮脏的解决方法,在桌面浏览器工作,悲伤地不在手机上:

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:

你必须检查auth.login而不是edge.create。在auth.login回调中调用edge.create操作。在edge.create action里面你可以定义你的回调来重定向或做任何你喜欢的事情。

You have to check for auth.login instead of edge.create. Inside the auth.login callback call the edge.create action. Inside the edge.create action you can now define your callback to redirect or do anything you like.

//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;
}

我知道这很脏,但是像我这样的门桌面浏览器。唯一的问题是如果用户没有登录但已经喜欢你的页面 - 你将无法抓住这种情况悲伤..但我同意 - 如果没有登录,edge.create不触发似乎是一个错误imo好吧。

I know this is pretty dirty but like this my like-gate works fine on desktop browsers. 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.

Btw。我正在使用自动初始化函数而不是FB.init()..

Btw. I'm using the auto init function instead of the FB.init()..

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

这篇关于FB像按钮edge.create事件登录后不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆