0

I was able to get the facebookConnectPlugin working on iOS using PhoneGap and Ionic. The issue is that when I try to run the exact same app on Android I get the error "facebookConnectPlugin is not defined". I'm using PhoneGap Build and am not building natively for Android.

Here are the steps I've taken to try to get it working on Android:

1) Generated a new keystore.

"C:\Program Files (x86)\Java\jre1.8.0_60\bin\keytool.exe" -genkey -v -keystore debug.keystore -alias androiddebugkey -keyalg RSA -keysize 2048 -validity 10000 

2) Created a new hash using this keystore.

"C:\Program Files (x86)\Java\jre1.8.0_60\bin\keytool.exe" -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

Used the password "android" everywhere it asked me for a password (for the keystore and the hash).

3) Added the following to my config.xml document:

<gap:plugin name="com.phonegap.plugins.facebookconnect" version="0.9.0">
    <param name="APP_ID" value="XXXXXXXXXX" />
    <param name="APP_NAME" value="MyApp" />
</gap:plugin>

The APP_ID I got from Facebook and the APP_NAME was the display name from Facebook.

4) Created an Android key in PhoneGap build uploading the keystore I specified and the alias "androiddebugkey". For all the passwords, including the certificate password I input my password "android".

5) Uploaded my application to PhoneGap build, installed it on an Android emulator (Lollipop using Visual Studio Emulator for Android) and tried to log into Facebook using the following code. This code fires after $ionicPlatform.ready.

var _this = this;    
var fbLoginSuccess = function (userData) {
    facebookConnectPlugin.api("me/?fields=id,email", ["public_profile"],
        function (result) {
        },
        function (error) {
            alert("Failed: " + error);
        }
    );
}

facebookConnectPlugin.login(["public_profile"],
    fbLoginSuccess,
    function (error) {
        alert(JSON.stringify(error));
    }
);

6) For my site at developers.facebook.com I added an Android app. The Google Play Package Name is the same as my "id" in the widget element in config.xml. For the Class Name, I specified the exact same thing as the id, but with ".MainActivity" appended to it. I inserted the Key Hash generated from Step 2 above into the Key Hashes field. I turned Single Sign On on. Not sure if that is correct or not.

I've spent days trying to figure this out with no luck. I'm not sure if the issue is with the hash, cordova, or some other Facebook permissions. Like I said earlier, it works fine on iOS. It's just Android that has the problem.

Any help would be very much appreciated.

oalbrecht
  • 413
  • 4
  • 11

1 Answers1

0

@oalbrecht,

I am posting this link with the hope you will read the entire document.

Top Mistakes by Developers new to Cordova/Phonegap

In fact your error was

3. Does not follow the blogs.

For you see, we have now move to a new repository on npm.org. This actually gets you another error

11. You need to get your plugins from NPM now.

How did I figure this out? I did a google search of your plugin: com.phonegap.plugins.facebookconnect

About three (3) links down is your plugin: FacebookConnect

The documentation says

REPOSITORY IS NOW DEPRECATED!!!

Please go here

READ THE DIRECTIONS CAREFULLY. This is an ugly plugin. The correct links are:

Your new plugin setting is:

<gap:plugin name="cordova-plugin-facebookconnect-orlando" source="npm" version="0.11.0">

Community
  • 1
  • 1
  • Thanks for your reply! I tried using the new plugin setting, but am now getting the error: In file included from /project/Zonar/Plugins/cordova-plugin-facebookconnect-orlando/FacebookConnectPlugin.m:11: Zonar/Plugins/cordova-plugin-facebookconnect-orlando/FacebookConnectPlugin.h:11:9: fatal error: 'FacebookSDK/FacebookSDK.h' file not found #import ^ 1 error generated. That's for iOS. I'm also getting errors for Android and WinPhone on PhoneGap Build (cloud service). – oalbrecht Oct 26 '15 at 03:08
  • If your code is on a public website, I'll have a look at it. I suspect multiple problems. –  Oct 26 '15 at 03:12
  • Unfortunately the project isn't on a public website. Have you gotten the FacebookConnect plugin to work on iOS and Android using PhoneGap Build? I've looked extensively online and I haven't seen anyone who's gotten it to work recently. It actually seems like the latest versions of the plugin don't work with PhoneGap Build based on what I've read. If you've gotten it to work somehow, I would be very thankful if you posted some more info on how you got it working. I really appreciate you taking the time to help me with this! – oalbrecht Oct 27 '15 at 02:16
  • No sorry. I do not like facebook, so I do not support facebook; I only support developers. On your issue, I have been forgetting to let people know -- iOS 9 is NOT official support. That means, anything you build right now for iOS 9 will not work. There are many bugs. [SEE](https://github.com/jessemonroy650/top-phonegap-mistakes/blob/master/current-tripping-points.md)... FWIW, I'm working to support my startup, and as I see it - it is my job to help all Cordova/Phonegap developers at this time. However, in a few weeks, I will turn towards IOT and Phonegap only. Best of Luck. –  Oct 27 '15 at 04:44