Question

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

When I try to log into facebook through the app on an android device (with the facebook app installed), I get this error:

Invalid android_key parameter J4INwYsuTyQ_LJc1d3WZ2HReg7M does not match any allowed android key. Configure your app key hashes at http://developers.facebook.com/apps/'app id'

I have copy-pasted this key into the key hashes section of my app's android settings but it still throws the same error when I try to log in using the app.

How can I get this app to log into facebook successfully?

OR: What is another way to enable an android app to log into facebook using phonegap?

Here are some things I have done:

  • In my facebook app's settings:

    • Set 'Package name' to the 'widget id' found in my phonegap config.xml.
    • Set 'Class name' to the Package name with '.ProjectActivity' appended to it.
    • Enabled 'Single Sign on' and disabled 'Deep linking'.
    • Made the app open to the public (through the 'Status & Review' section.
  • In my phonegap config.xml (found in the /www directory in phonegap project):

    • Entered APP_ID as the ID found in my facebook app dashboard
    • Entered APP_NAME as the 'Namespace' found in my facebook app settings
  • In my phonegap build app settings:

Was it helpful?

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.

OTHER TIPS

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') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
if (typeof FB == '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');
});

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

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

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

function login() {
    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!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top