This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by quidmonkey

So like many of you, I want to integrate my Impact app with Facebook. I'd like to make a simple leaderboard similar to the one used by the Mangu.

Making the backend is the part I know how to do, what I don't know how to do is sync my app with Facebook. I reviewed the Javascript SDK, and I understand I initialize the connection with FB.init(), but what I'm unclear on is how I do authenticate and grab a user's info?

Any help would be greatly appreciated. Thx!

1 decade ago by dominic

I did this for the Facebook version of Z-Type and used Playtomic for the Scoreboards. Sadly, the Facebook API is a huge pain in the ass :/

Here's a plugin I wrote for that:


ig.Facebook = {
	appId: null,
	callback: null,
	session: null,
	me: null,
	cache: {}

ig.Facebook.Init = function( appId, appURL, perms, callback ) {
	ig.Facebook.appId = appId;
	ig.Facebook.appURL = appURL;
	ig.Facebook.callback = callback;
	// Not running in an IFrame on Facebook? Forward to it!
	if( ! || == window ) { = ig.Facebook.appURL;
	// This function will be called as soon as the FB API is loaded
	window.fbAsyncInit = function() {
			appId: ig.Facebook.appId,
			status: true, // check login status
			xfbml: true  // parse XFBML
		if( window.opera ) {
			FB.XD._transport = "postmessage";
		// Make sure the User is logged in and we have all needed permissions.
		// If not, forward to the login/request permission dialog on FB
		FB.getLoginStatus(function(response) {			
			if( response.session ) {				
				ig.Facebook.session = response.session;
				if( ig.Facebook.callback ) {
			else { =
					'' + ig.Facebook.appId +
					'&redirect_uri=' + ig.Facebook.appURL +
					'&scope=' + perms;
	// Load the FB API
	var div = ig.$new('div'); = 'fb-root';
	var script = ig.$new('script');
	script.type = 'text/javascript';
	script.src = '';
	script.async = true;

// Simple Caching "Proxy" for FB.api()
ig.Facebook.CachedAPI = function( req, callback ) {
	if( ig.Facebook.cache[req] ) {
		callback( ig.Facebook.cache[req] );
	else {
		FB.api( req, function( response ) {
			ig.Facebook.cache[req] = response;
			callback( response );


Put it in lib/plugins/facebook.js and require the plugins.facebook module in your main.js. The Facebook JS API is automatically loaded by the plugin, you don&039;t need to load it through a #<script> tag on your page.

Put your ig.main() in a callback for when the Facebook API is ready:
	'1234', // Your App ID
	'email,read_stream', // Permissions that your App requires
		ig.main( '#canvas', ZType, 60, 360, 640, 1 );	

You can then make API calls in your game like this:
ig.Facebook.CachedAPI( '/me', function( data ){
	// 'data' is the response from the FB API
	// Do something with it here: e.g. submit a score with the

1 decade ago by quidmonkey

Awesome. I was gonna do just this. Thank you!

1 decade ago by Karios

A quick fix if you are getting issues with the plugin. Since Facebook requires everything to be https now, you should change this line:
to this line
Page 1 of 1
« first « previous next › last »