2

我实际上正在使用这个 js 函数进行 facebook 连接。

window.fbAsyncInit = function(){
   FB.init({ 
    appId: '371***********',
     status: true,
      cookie: true,
       xfbml: true ,
       oauth:true,
       channelUrl: '<?php echo base_url(); ?>fb-channel-file.php' //this domain
     });
};
(function() {
   var e = document.createElement('script');
   e.type = 'text/javascript';
   e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
   e.async = true;
   document.getElementById("fb-root").appendChild(e);
}());
// FB LOGIN -->

function FBlogin(){
  FB.getLoginStatus(function(r){
    FB.login(function(response) {
      if(response.authResponse) {
        $.ajax({
          type:'GET',
          url: _config_base_url+'/auth/ajax_login',
          dataType:'json',
          data:{'fb_at':response.authResponse.accessToken},
          beforeSend:function(){
            notify('Loading ...',false,'notify-info');
          },
          error:function(_response){
              notify('An error occurred, please try again later.',false); 

            },
            success:function(json){
              notify_destroy();

              window.location.href= _config_base_url+'/profile';

            }
          });
      } else {}
    },{scope:'email'/*,user_birthday,user_location*/});
  });
}

现在我想重现相同/完全相同的允许人们通过连接的功能Twitter,我只是将其转为Google+,但我真的不明白如何将其转为Twitter oAuth.

任何想法?

4

1 回答 1

3

更新

原始答案

  • 这个对JavaScript OAuth 使用 Twitter 登录的答案读起来像是由于安全原因,它不可能或不是最好的方法。

    这样做的问题是任何查看您的页面的人现在也可以查看您的消费者密钥和必须保密的秘密。

    ...

    Twitter 确实声明必须尽一切可能将这些值保密以避免这种情况发生

    不幸的是,目前没有办法在基于浏览器的 JavaScript 中安全地使用 oAuth。

  • jsOAuth可能会有所帮助,但正如上面的答案所述,安全性是一个问题。

    jsOAuth 是一个实现 OAuth 协议的 javascript 库。jsOAuth 旨在形成 Twitter 和 Yahoo 等自定义客户端的基础。

    ...

    出于安全原因,jsOAuth 不在浏览器中运行。此处仅提及浏览器用于运行测试套件。

于 2013-01-16T13:20:33.137 回答