Facebook的Javascript SDK可以与较早的Facebook API一起工作吗? [英] Can Facebook's Javascript SDK work together with the older Facebook API?

查看:171
本文介绍了Facebook的Javascript SDK可以与较早的Facebook API一起工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在有代码可以通过以下方式加载当前的Facebook Javascript SDK:

  window.fbAsyncInit = function(){
FB.init({appId:'218565466928',status:true,cookie:true,
xfbml:true});
};
// [...]初始化它

还有代码可以使用旧的Facebook API由

  init_fb_connect('Connect','XFBML',:js =>:jquery,:app_settings => '{ifUserNotConnected:fb_user_not_connected}')do 

这是 Facebooker Rubygem。他们可以一起工作吗?如果我有两个,那么新添加的Like按钮将不起作用。如果我删除旧的Facebooker代码,那么使用Facebook登录和共享按钮将不起作用。任何想法?






更新:旧代码执行以下操作:

 < a class =facebook-connect-linkhref =#
onclick =; FB.Connect.requireSession fb_after_connect,null,true); return false;
rel =nofollow>使用Facebook登录< / a>

 < a href =#onclick =FB.Connect.streamPublish('',{'name':'Some product name'... 
pre>

  $('。login-button') .each(function(){
FB.XFBML.Host.addElement(new FB.XFBML.LoginButton(this));
})


解决方案

转换JavaScript API比较容易,我不知道你的服务器端会受到多大的影响,您可能需要的基本方法:

  //检查用户是否正在登录
FB.getLoginStatus (function(response){
if(response.session){
//登录和连接的用户,你认识的人
} else {
//没有用户会话可用,有人你不知道
}
});

//用户注销/登录时触发回调
FB.Event.subscribe('auth.sessionChange ',功能(response){
//做某事与response.session
});

//强制登录(点击登录btn)。
FB.login(function(response){
if(response.session){
//用户成功登录
fb_after_connect();
} else {
//用户取消登录
}
});

//发布到Feed。
FB.api('/ me / feed','post',{body:message},function(response){
if(!response || response.error){
alert('Error occured');
} else {
alert('Post ID:'+ response);
}
});

如果您不想转换为新的API,那么您可以像iframe一样嵌入按钮。迟早你不得不转换你的项目,所以现在也可以这样做。


Can the current Facebook Javascript SDK work with older Facebook API library?

Right now there is code to load the current Facebook Javascript SDK by:

window.fbAsyncInit = function() {
    FB.init({appId: '218565466928', status: true, cookie: true,
             xfbml: true});
};
// [...] initialize it

And there is code to use the old Facebook API by

init_fb_connect('Connect', 'XFBML', :js => :jquery, :app_settings=> '{ifUserNotConnected: fb_user_not_connected}' ) do

which is the Facebooker Rubygem. Can they work together somehow? If I have both, then the newly added "Like" button won't work. If I remove the older Facebooker code, then the "Login with Facebook" and "Share" button won't work. Any ideas?


Update: the older code do things like:

<a class="facebook-connect-link " href="#" 
  onclick="; FB.Connect.requireSession(fb_after_connect, null, true); return false;"
  rel="nofollow">Sign in with Facebook</a>  

and

<a href="#" onclick="FB.Connect.streamPublish('', {'name': 'Some product name' ...

and

  $('.login-button').each(function() {
    FB.XFBML.Host.addElement(new FB.XFBML.LoginButton(this));  
  })

解决方案

Converting the JavaScript API is relatively easy. I am not sure how much your server side will be affected though. Here are the basic methods that you would probably need:

//Check if user is logged in right now.
FB.getLoginStatus(function(response) {
  if (response.session) {
    // logged in and connected user, someone you know
  } else {
    // no user session available, someone you dont know
  }
});

//Callback fired when user logs out/logs in.
FB.Event.subscribe('auth.sessionChange', function(response) {
  // do something with response.session
});

//To force login (on login btn click).
FB.login(function(response) {
  if (response.session) {
    // user successfully logged in
    fb_after_connect();
  } else {
    // user cancelled login
  }
});

//Post to feed.
FB.api('/me/feed', 'post', { body: "message" }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response);
  }
});

If you don't want to convert to the new API then you can embed like button as iframe. Sooner or later you would have to convert your project anyway so might as well do it now.

这篇关于Facebook的Javascript SDK可以与较早的Facebook API一起工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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