經過大約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上工作。
想法?
你有沒有把facebook網站列入白名單? – Leo
將connect.facebook.net等添加到config.xml中。 –
Leo
它是白名單(我通過從桌面版本登錄來驗證它)。訪問原點定義爲:所以它不應該'不成爲問題 –