Skip to content

Commit

Permalink
updated iOS SDK, Android SDK, Readme and is now plugman compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
aogilvie committed Feb 3, 2014
1 parent 67e81e1 commit ee6c32d
Show file tree
Hide file tree
Showing 186 changed files with 28,412 additions and 1,775 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ test/www/*.js
*.xcworkspace
!default.xcworkspace
xcuserdata

# Android Projects

*.apk
*.ap_
*.dex
*.class

bin/
gen/

.gradle/
build/

local.properties
proguard/
109 changes: 101 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ This is the official plugin for Facebook in Apache Cordova/PhoneGap!

The Facebook plugin for [Apache Cordova](http://incubator.apache.org/cordova/) allows you to use the same JavaScript code in your Cordova application as you use in your web application. However, unlike in the browser, the Cordova application will use the native Facebook app to perform Single Sign On for the user. If this is not possible then the sign on will degrade gracefully using the standard dialog based authentication.

* Supported on PhoneGap (Cordova) v3.0.0 and above.
* Supported on PhoneGap (Cordova) v3.3.0 and above.
* This plugin is build for
* iOS FacebookSDK 3.11.1
* Android FacebookSDK 3.6.0

## Facebook Requirements and Set-Up

Expand Down Expand Up @@ -178,14 +181,104 @@ Make sure you add the scheme to your [PROJECTNAME]-Info.plist (located as one of
</pre>

## Automatic Installation
This plugin is based on [plugman](https://git-wip-us.apache.org/repos/asf?p=cordova-plugman.git;a=summary). To install it to your app, simply execute plugman as follows; It does not currently work with plugman at all. WORK IN PROGRESS

plugman install --platform [PLATFORM] --project [TARGET-PATH] --plugin [PLUGIN-PATH] --variable APP_ID="[APP_ID]" --variable APP_NAME="[APP_NAME]"
This plugin is based on [plugman](https://git-wip-us.apache.org/repos/asf?p=cordova-plugman.git;a=summary). To install it to your app, execute the following (and replace variables where necessary)...

### iOS


cordova create myApp

cd myApp/

cordova platform add ios

cordova -d plugin add /Users/your/path/here/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"

### Android

cordova create myApp

cd myApp/

cordova platform add android

cordova -d plugin add /Users/your/path/here/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"

**Android requires an additional step which is to reference the FacebookSDK project as a library to your project.**

Open your project in Eclipse (New > Project... Existing Android project from source), import everything (***see Img. 1***).

![image](./android_setup_1.png) ***Img. 1***

In Eclipse, right click your project folder in the left-had column. Select "Properties", select Android in the left column and in the right side of the window add FacebookSDK as a library (***see Img. 2***).

![image](./android_setup_2.png) ***Img. 2***

## JS API

###facebookConnectPlugin.login(Function success, Function failure)

Success function returns an Object like;

{
id: "634565435",
lastName: "bob"
...
}

where
[PLATFORM] = ios or android
[TARGET-PATH] = path to folder containing your phonegap project
[PLUGIN-PATH] = path to folder containing this plugin
[APP_ID] = Your APP_ID as registered on Facebook
Failure function returns an error String.

###facebookConnectPlugin.logout(Function success, Function failure)

###facebookConnectPlugin.getLoginStatus(Function success, Function failure)

Success function returns a status String.

###facebookConnectPlugin.showDialog(JSONObject options, Function success, Function failure)

Example options:

{
method: "feed" | "apprequests"
}

Success function returns an Object with `postId` as String.
Failure function returns an error String.

## Sample JavaScript Code

### Login

In your `onDeviceReady` event add the following

var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}

facebookConnectPlugin.login(["basic_info"],
fbLoginSuccess,
function (error) { alert("" + error) }
);

### Get Status & Post-to-wall

For a more instructive example change the above `fbLoginSuccess` to;

var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
facebookConnectPlugin.getLoginStatus(
function (status) {
alert("current status: " + JSON.stringify(status));
var options = { method:"feed" };
facebookConnectPlugin.showDialog(options,
function (result) {
alert("Posted. " + JSON.stringify(result)); },
function (e) {
alert("Failed: " + e);
});
}
);
};

Binary file added android_setup_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android_setup_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 14 additions & 17 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,27 @@
<platform name="android">

<config-file target="config.xml" parent="/*">
<feature name="org.apache.cordova.facebook.Connect">
<feature name="FacebookConnectPlugin">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
</config-file>

<source-file src="src/android/facebook/res/values/facebookconnect.xml" target-dir="res/values" />
<config-file target="res/values/facebookconnect.xml" parent="/*">
<string name="fb_app_id">$APP_ID</string>
<string name="fb_app_name">$APP_NAME</string>
</config-file>

<config-file target="AndroidManifest.xml" parent="application">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id"/>
<activity android:label="@string/fb_app_name" android:name="com.facebook.LoginActivity"></activity>
</config-file>

<!-- res files -->
<source-file src="src/android/facebook/res/drawable/close.png" target-dir="res/drawable" />
<source-file src="src/android/facebook/res/drawable/facebook_icon.png" target-dir="res/drawable" />
<source-file src="src/android/facebook/res/drawable-hdpi/close.png" target-dir="res/drawable-hdpi" />
<source-file src="src/android/facebook/res/drawable-hdpi/facebook_icon.png" target-dir="res/drawable-hdpi" />
<source-file src="src/android/facebook/res/drawable-ldpi/close.png" target-dir="res/drawable-ldpi" />
<source-file src="src/android/facebook/res/drawable-ldpi/facebook_icon.png" target-dir="res/drawable-ldpi" />
<source-file src="src/android/facebook/res/drawable-xhdpi/close.png" target-dir="res/drawable-xhdpi" />
<!-- copy Facebook Lib project -->
<source-file src="src/android/facebook/FacebookLib" target-dir="./" />

<!-- cordova plugin src files -->
<source-file src="src/android/ConnectPlugin.java" target-dir="src/org/apache/cordova/facebook" />

<!-- facebook src files -->
<source-file src="src/android/facebook/AsyncFacebookRunner.java" target-dir="src/com/facebook/android" />
<source-file src="src/android/facebook/DialogError.java" target-dir="src/com/facebook/android" />
<source-file src="src/android/facebook/Facebook.java" target-dir="src/com/facebook/android" />
<source-file src="src/android/facebook/FacebookError.java" target-dir="src/com/facebook/android" />
<source-file src="src/android/facebook/FbDialog.java" target-dir="src/com/facebook/android" />
<source-file src="src/android/facebook/Util.java" target-dir="src/com/facebook/android" />

</platform>

Expand Down
Loading

0 comments on commit ee6c32d

Please sign in to comment.