Skip to content

Instantly share code, notes, and snippets.

@racerpeter
Created September 15, 2011 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save racerpeter/1220783 to your computer and use it in GitHub Desktop.
Save racerpeter/1220783 to your computer and use it in GitHub Desktop.
PG = ( typeof PG == 'undefined' ? {} : PG );
PG.FB = {
init: function(apiKey) {
// create the fb-root element if it doesn't exist
if (!document.getElementById('fb-root')) {
var elem = document.createElement('div');
elem.id = 'fb-root';
document.body.appendChild(elem);
}
PhoneGap.exec(function(e) {
if(e.session && e.session.uid) {
FB.Auth.setSession(e.session, 'connected');
}
}, null, 'com.phonegap.facebook.Connect', 'init', [apiKey]);
},
login: function(a, b) {
b = b || { perms: '' };
PhoneGap.exec(function(e) { // login
FB.Auth.setSession(e.session, 'connected');
if (a) a(e);
}, null, 'com.phonegap.facebook.Connect', 'login', b.perms.split(',') );
},
logout: function(cb) {
PhoneGap.exec(function(e) {
FB.Auth.setSession(null, 'notConnected');
if (cb) cb(e);
}, null, 'com.phonegap.facebook.Connect', 'logout', []);
},
getLoginStatus: function(cb) {
PhoneGap.exec(function(e) {
if (cb) cb(e);
}, null, 'com.phonegap.facebook.Connect', 'getLoginStatus', []);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment