问题
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.
回答1:
@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:
- github
- npm
Your new plugin setting is:
<gap:plugin name="cordova-plugin-facebookconnect-orlando" source="npm" version="0.11.0">
来源:https://stackoverflow.com/questions/33314552/facebookconnectplugin-is-not-defined-phonegap-build-android