Skip to content Skip to sidebar Skip to footer

Phonegap Build - Facebook Connect Plugin - Invalid Android_key Parameter Error

I'm running example code (found below) through phonegap build to produce an android apk. https://github.com/phonegap-build/FacebookConnect/blob/master/example/Simple/index.html Whe

Solution 1:

I think you should use facebook phonegap plugin as your authentication.

Download and install into your cordova project.

https://github.com/phonegap/phonegap-facebook-plugin

Use this command to install it.

cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="xxxxxxxxxxxxx" --variable APP_NAME=“xxxxxxxx”

Then setup your facebook app here:

http://developers.facebook.com/apps/

Then make sure you have this script in your project.

cdv-plugin-fb-connect.js
facebook-js-sdk.js

After that, paste this code into your main script

if ((typeof cordova == 'undefined') && (typeofCordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
if (typeofCDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
if (typeofFB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');
FB.Event.subscribe('auth.login', function(response) {
    //alert('auth.login event');
});
FB.Event.subscribe('auth.logout', function(response) {
    //alert('auth.logout event');
});
FB.Event.subscribe('auth.sessionChange', function(response) {
    //alert('auth.sessionChange event');
});
FB.Event.subscribe('auth.statusChange', function(response) {
    //alert('auth.statusChange event');
});

functiongetSession() {
    alert("session: " + JSON.stringify(FB.getSession()));
}

functiongetLoginStatus() {
    FB.getLoginStatus(function(response) {
        if (response.status == 'connected') {
            alert('logged in');
        } else {
            alert('not logged in');
        }
    });
}
var friendIDs = [];
var fdata;

functionlogout() {
    FB.logout(function(response) {
        alert('logged out');
        window.location.replace("#login");
    });
}

functionlogin() {
    FB.login(

    function(response) {
        if (response.authResponse) {
            alert('logged in');
            FB.api('/me', function(me) {
                if (me.id) {
                                    localStorage.id = me.id;
                    localStorage.email = me.email;
                    localStorage.name = me.name;
                    window.location.replace("#home");
                }
                else {
                    alert('No Internet Connection. Click OK to exit app');
                    navigator.app.exitApp();
                }
            });
        } else {
            alert('not logged in');
        }
    }, {
        scope: "email"
    });
}

document.addEventListener('deviceready', function() {
    try {
        //alert('Device is ready! Make sure you set your app_id below this alert.');FB.init({
            appId: "appid",
            nativeInterface: CDV.FB,
            useCachedDialogs: false
        });
        document.getElementById('data').innerHTML = "";
    } catch (e) {
        alert(e);
    }
}, false);

use login() to login . Enjoy!!

Solution 2:

I successfully made an app which can log into facebook by using the phonegap-facebook-plugin and by building my cordova/phonegap project locally.

I made a new cordova project and added the android platform for this project, following the instructions here: http://docs.phonegap.com/en/3.4.0/guide_overview_index.md.html#Overview

In doing this I discovered I had made my previous project using an older cordova version (3.1) un-intentionally and that I hadn't installed the cordova command line interface. There may have been other issues with the way I made my first project.

I then added the phonegap-facebook-plugin found here: https://github.com/phonegap/phonegap-facebook-plugin using this command (from my project location):

    cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable       APP_ID="xxxxxxxxxxxxx" --variable APP_NAME=“xxxxxxxx”

(replacing APP_ID value with my facebook app id and APP_NAME value with my app's namespace).

I then replaced my index.html with the example index file found at the phonegap-facebook-plugin github page + /blob/master/example/Simple/index.html (replacing the app_id value with my app id).

I then ran the app straight to my android device using:

    cordova run android

In this app, I'm able to use the interface provided by the example to login, post to my own or friends' walls etc. Using this new project (with updated cordova version) I may be able to use phonegap build but I haven't tried yet.

Thanks to Dato' Mohammad Nurdin for the suggestion to use this plugin.

Post a Comment for "Phonegap Build - Facebook Connect Plugin - Invalid Android_key Parameter Error"