phonegap facebook プラグインのすべてのバージョンを実装しようとして約 2 日後、私はそれをあきらめて、アプリにプレーンな JS ログイン システムを実装することにしました。正直なところ、ネイティブのログイン システムは、このプラグインを扱う価値がありません...
Facebook 開発者サイトの指示に従いましたが、ログインはデスクトップ ブラウザーで完全に機能します。phonegapでコンパイルしてAndroidデバイスで実行しようとすると、問題が発生します。ログインボタンを押すと、「FB is not defined at...」というメッセージが表示されます。これは、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 で動作させることはできません。
アイデア?