1

我正在(jquery mobile)的帮助下制作一个Android应用程序,如果我想在我的应用程序中使用facebook登录需要你的帮助,我该怎么做这些事情请帮帮我

在有 AppID 和 AppSecret

请逐步向我解释

4

1 回答 1

0
1) Add ChildBrowser Phongap Plugin for android in your app.

2) Your login page add this code
$("#btn_log_facebook").on("click", function(event){

if(event.handled !== true)    {

    var fb = FBConnect.install();
    var client_id = your_client_id;

    var redir_url = your_redir_url; 

    fb.connect(client_id,redir_url,"touch");

    event.handled = true;

 }
 return false;    
});

3) Create fb_connect.js file  

function FBConnect()
 {
if(window.plugins.childBrowser == null)
{
    ChildBrowser.install();
}
 }

FBConnect.prototype.connect = function(client_id,redirect_uri,display)
{
 this.client_id = client_id;
 this.redirect_uri = redirect_uri;

 var authorize_url  = "https://graph.facebook.com/oauth/authorize?";
    authorize_url += "client_id=" + client_id;
    authorize_url += "&redirect_uri=" + redirect_uri;
    authorize_url += "&display="+ ( display ? display : "touch" );
    authorize_url += "&type=user_agent";

     var ref = window.open(authorize_url, 'random_string', 'location=no');
     ref.addEventListener('loadstart', function(event) {
                     //console.log(event.type + ' - ' + event.url);
} );
ref.addEventListener('loadstop', function(event) {
    var access_token = event.url.split("access_token=")[1];
    var error_reason = event.url.split("error_reason=")[1];

     if(access_token != undefined){
           access_token = access_token.split("&")[0];
           loginWithFacebookUserInfo(access_token);
         setTimeout(function() {
                    ref.close();
                    }, 5000);

     }
     if(error_reason != undefined){

          window.location.href = "register.html";
          setTimeout(function() {
                    ref.close();
                    }, 5000);
     }
        //console.log(event.url); alert(event.type + ' - ' + event.url);

 } );
 ref.addEventListener('exit', function(event) {
                     //console.log(event.type);
} );  

}
于 2013-10-04T05:46:36.980 回答