2013-10-04 89 views
1

我正在(jquery mobile)幫助下製作Android應用程序,如果我想在我的應用程序中使用Facebook登錄,需要您的幫助,我該如何做這些事情請幫助我出去使用jQuery移動應用程序中的Facebook登錄

具有的AppID和AppSecret

請給我解釋一下步驟步驟過程

回答

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

} 
+0

謝謝你,我嘗試用這些代碼 –

+0

@Atul深受歡迎。它適用於我的iOS和Android兩種。但你應該知道的ChildBrowser和InAppBrowser – Ved

+0

我沒有childBrowser和InAppBrowser的知識 –

相關問題