Skip to content

Commit

Permalink
updated simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengill committed Mar 12, 2012
1 parent 4b94659 commit 0d76ca9
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 114 deletions.
21 changes: 10 additions & 11 deletions README.md
Expand Up @@ -11,7 +11,7 @@ This is all licensed under MIT except for `app/www/facebook_js_sdk.js` which is

# Requirements

* PhoneGap v1.0+
* PhoneGap v1.0 - 1.4.1

The Facebook SDK (both native and JavaScript) is changing independent of this plugin. The working versions of the Facebook Android, JS and iOS SDKs are bundled in this project via git submodules.

Expand Down Expand Up @@ -40,6 +40,8 @@ the modified file to get it working with this plugin. This plugin
monkey-patches some of the facebook-js-sdk methods to hook in an
interface into the native Facebook SDKs.

`lib/facebook_js_sdk` is the modified facebook-js-sdk. It already includes the hooks to work with this plugin.

`native/android` and `native/ios` contain the native code for the plugin for both Android and iOS platforms.

`www/pg-plugin-fb-connect.js` is the JavaScript code for the plugin, this defines the JS API.
Expand Down Expand Up @@ -104,7 +106,7 @@ You can run the application from either the command line (`ant clean && ant debu

## iOS (Mac OS X)

NOTE: If you are having problems with SBJSON conflicts, download the latest version of git clone the latest callback-ios code, build the installer, and run the installer to get updated!
NOTE: If you are having problems with SBJSON conflicts, download the latest version of git clone the latest cordova-ios code, build the installer, and run the installer to get updated!

1. Create a basic PhoneGap iOS application. See http://www.phonegap.com/start/#ios-x4
2. From the **PhoneGap Facebook Connect Plugin** folder copy the contents of the **native/ios** folder into your app in Xcode (usually in the **Plugins** folder group). Make sure it is added as a "group" (yellow folder)
Expand All @@ -114,6 +116,7 @@ NOTE: If you are having problems with SBJSON conflicts, download the latest vers
6. for Xcode 4, you will need to build it once, and heed the warning - this is an Xcode 4 template limitation. The warning instructions will tell you to drag copy the **www** folder into the project in Xcode (add as a **folder reference** which is a blue folder).
7. Under the group **Supporting Files**, find your **[PROJECTNAME]-Info.plist**, right-click on the file and select **Open As -> Source Code**, add the **URL Scheme** from the section below (you will need your Facebook **APP_ID**)
8. Run **git submodule update --init** to initialize and pull down the versions of the JS and iOS Facebook SDKs that work with this plugin; they will end up under **lib/**.
IGNORE STEP 9 & 10
9. Next, **build and patch** the JS file:

cd lib/facebook-js-sdk && php all.js.php >> ../facebook_js_sdk.js && cd .. && patch < facebook-js-patch
Expand All @@ -122,15 +125,11 @@ NOTE: If you are having problems with SBJSON conflicts, download the latest vers

11. From the **PhoneGap Facebook Connect Plugin** folder copy the file **lib/facebook_js_sdk.js** into the **www** directory in Xcode (don't forget to add script tags in your index.html to reference the .js file copied over)

12. From `lib/facebook-ios-sdk/src` Drag the **facebook-ios-sdk.xcodeproj** file into your project, this will create it as a sub-project (change it's Base SDK to 'Latest iOS')
13. Click on your project's icon (the root element) in Project Navigator, select your **Target**, and the **Build Phases** tab.
14. From the **Build Phases** tab, expand **Target Dependencies**, then click on the **+** button
15. Add the build product from the **facebook-ios-sdk sub-project**
16. From the **Build Settings** tab, search for **Header Search Paths**
17. Add the value **/Users/Shared/PhoneGap/Frameworks/PhoneGap.framework/Headers**
18. From the **facebook-ios-sdk.xcodeproj** sub-project, drag out the **FBConnect** folder into your project's **Plugins** folder, and add it as a group (yellow folder).
19. Add the Facebook domains to the ExternalHosts lists, as described below.
20. Run the application in Xcode.
12. From `lib/facebook-ios-sdk` Remove **facebook-ios-sdk.xcodeproj** and **facebook_ios_sdk_Prefix.pch** files. Drag the **src** folder into your project under **Plugins** folder and make sure it is added as a "group" (yellow folder)
13. Click on your project's icon (the root element) in Project Navigator, select your **Target**, then the **Build Settings** tab, search for **Header Search Paths**.
14. Add the value **/Users/Shared/PhoneGap/Frameworks/PhoneGap.framework/Headers**
15. Add the Facebook domains to the ExternalHosts lists, as described below.
17. Run the application in Xcode.


### iOS URL Whitelist
Expand Down
157 changes: 157 additions & 0 deletions example/Simple/www/index.html
@@ -0,0 +1,157 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="login()">Login</button>
<button onclick="me()">Me</button>
<button onclick="getSession()">Get session</button>
<button onclick="getLoginStatus()">Get login</button>
<button onclick="logout()">Logout</button>
<button onclick="facebookWallPost()">facebookWallPost</button>
<button onclick="publishStoryFriend()">friendstory</button>

<div id="data">loading ...</div>

<script src="http://localhost:8080/target/target-script-min.js#anonymous"></script>
<!-- phonegap -->
<script src="phonegap-1.4.1.js"></script>
<!-- phonegap facebook plugin -->
<script src="pg-plugin-fb-connect.js"></script>
<!-- facebook js sdk -->
<script src="facebook_js_sdk.js"></script>

<script>

if (typeof PhoneGap == 'undefined') alert('PhoneGap variable does not exist. Check that you have included phonegap.js correctly');
if (typeof PG == 'undefined') alert('PG variable does not exist. Check that you have included pg-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 me() {
FB.api('/me/friends', { fields: 'id, name, picture' }, function(response) {
if (response.error) {
alert(JSON.stringify(response.error));
} else {
var data = document.getElementById('data');
fdata=response.data;
console.log("fdata: "+fdata);
response.data.forEach(function(item) {
var d = document.createElement('div');
d.innerHTML = "<img src="+item.picture+"/>"+item.name;
data.appendChild(d);
});
}
var friends = response.data;
console.log(friends.length);
for (var k = 0; k < friends.length && k < 200; k++) {
var friend = friends[k];
var index = 1;

friendIDs[k] = friend.id;
//friendsInfo[k] = friend;
}
console.log("friendId's: "+friendIDs);
});
}

function logout() {
FB.logout(function(response) {
alert('logged out');
});
}

function login() {
FB.login(
function(response) {
if (response.session) {
alert('logged in');
} else {
alert('not logged in');
}
},
{ scope: "email" }
);
}


function facebookWallPost() {
console.log('Debug 1');
var params = {
method: 'feed',
name: 'Facebook Dialogs',
from: '116204184',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
};
console.log(params);
FB.ui(params, function(obj) { console.log(obj);});
}

function publishStoryFriend() {
randNum = Math.floor ( Math.random() * friendIDs.length );

var friendID = friendIDs[randNum];
if (friendID == undefined){
alert('please click the me button to get a list of friends first');
}else{
console.log("friend id: " + friendID );
console.log('Opening a dialog for friendID: ', friendID);
var params = {
method: 'feed',
to: friendID.toString(),
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
};
FB.ui(params, function(obj) { console.log(obj);});
}
}

document.addEventListener('deviceready', function() {
try {
alert('Device is ready! Make sure you set your app_id below this alert.');
FB.init({ appId: "273476932664248", nativeInterface: PG.FB, useCachedDialogs: true });
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}, false);
</script>
<div id="log"></div>
</body>
</html>
102 changes: 0 additions & 102 deletions example/www/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion native/ios/FacebookConnectPlugin.m
Expand Up @@ -10,7 +10,7 @@
#import "FacebookConnectPlugin.h"
#import "JSON.h"

#define APP_SECRET @"3fa440c0919afdd20a957c6cce288480"
#define APP_SECRET @"ReplaceMe"

@implementation FacebookConnectPlugin

Expand Down

0 comments on commit 0d76ca9

Please sign in to comment.