2013-08-19 45 views
1

經過大約2天的嘗試實現phonegap facebook插件的每個版本,我決定放棄它並在我的應用中實現普通的JS登錄系統。說實話,原生登錄系統是不值得處理這個插件...Facebook登錄在瀏覽器中正常工作,但無法在手機上使用

我遵循facebook開發者網站上的說明,我的登錄在桌面瀏覽器上完美工作。問題開始後,我用phonegap編譯它,並嘗試在Android設備上運行它。 當我按下登錄按鈕時,我得到一個 「FB未定義在...」 這是因嘗試訪問FB.login()方法而產生的結果。

相關代碼:

window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : 'XXXXXXXXXX', // contains my App ID 
     channelUrl : 'YYYYYYYYYYYY', // contains my Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 


    FB.Event.subscribe('auth.authResponseChange', function(response) { 
     // Here we specify what we do with the response anytime this event occurs. 
     if (response.status === 'connected') { 
      testAPI(); 
      active_access_token = response.authResponse.accessToken; 
      $.mobile.changePage("#main_page"); 
     } else if (response.status === 'not_authorized') { 
      FB.login(); 
     } else { 
      FB.login(); 
     } 
    }); 

}; 

// Load the SDK asynchronously 
(function(d){ 
    console.log ("async load started!"); 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
}(document)); 


function testAPI() { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
} 

按鈕接線:

function set_buttons() { 
    $("#facebook_login_button").click(function(){ 
     console.log("login attempt"); 
     FB.login(); 
    }); 

再次,這完全在瀏覽器中。 phonegap編譯後,我不能讓它在android上工作。

想法?

+1

你有沒有把facebook網站列入白名單? – Leo

+0

將connect.facebook.net等添加到config.xml中。 Leo

+0

它是白名單(我通過從桌面版本登錄來驗證它)。訪問原點定義爲:所以它不應該'不成爲問題 –

回答

2

好吧,我理解了它...

因爲我從一個運行的locahost它我加的 「http:」 來

js.src = "//connect.facebook.net/en_US/all.js"; 

所以現在:

js.src = "http://connect.facebook.net/en_US/all.js"; 
+0

在我的情況下,它不工作任何其他解決方案@z_av請提供! –

0

嘗試轉到您的Facebook應用>設置>高級,並在「有效的OAuth重定向URI」上添加正確的網址

0

對我來說,它需要在iOS部分下的開發者Facebook應用設置中添加BundleID。 這可能會幫助我的船上的其他人。

相關問題