Love heart
GamePrefabs? Click the button: 

Home > Products > Advanced Facebook GRAPH API (JS & C#)

Advanced Facebook GRAPH API (JS & C#)



Preview demo

Preview

Compatible with: Unity 3.x

Connect your Unity application to Facebook using the new Facebook Graph API.

This prefab includes the PHP and Unity Javascript code you need to make a Unity game/application using data and pictures from Facebook. Have your players...

  • invite their friends,
  • send gifts or
  • post to their facebook walls...

...all from within the Unity player! No nasty overlay windows at all.

On top of that, you can save custom application data (such as user scores or configuration) associated with their Facebook account, so they can access it from anywhere they can log in to Facebook.

This version works with Unity v3 and requires a web host running PHP and a MySQL database.

Documentation includes:

  • Installation (WebServer side, Facebook App settings and Unity Player)
  • Supported function methods
  • Using 'gifts'
  • Callback methods
  • Advanced - extending the API

UPDATED:

New Features include:

  • Prefab now includes both C# and Javascript code!
  • Extended "permissions example"
  • Safari click fix - work around for Safari third party cookie restrictions.

UPDATED: v1.2

  • Updated documentation to reflect Facebook changes
  • Increased time before authentication time-out

Enjoy!

Added on November 13, 2010 in Code

Buy

Indie license 85
Commercial license 175

Please login to buy this product.

What license should I pick?

Comments

log in to comment


Xraller

Does this one work for iPhone?

on November 15, 2010

Flimgoblin

Hi Xraller, this one's just for Facebook Canvas applications (i.e. apps.facebook.com) - there's no support for mobile.

on November 15, 2010

Overhill

this is what I get in the end on my facebook application after going thru your tutorial. "Fatal error: Call to undefined function json_decode() in /myURL/initialise.php on line 15"

on November 19, 2010

Flimgoblin

Hi @Overhill,

Looks like you've got a version of PHP older than 5.2, or it's had json disabled for some reason.

You can install a PEAR PHP library that gives you this functionality in older versions:

See: http://www.epigroove.com/posts/97/howtousejsoninphp4orphp_51x

Cheers, Flimgoblin

on November 19, 2010

Flimgoblin

Sorry, that link messed up: How to use JSON in PHP 4 or 5.1

on November 19, 2010

Houndie

For some reason I am getting the following error when trying to access things through facebook:


Invalid data file

Data file is corrupt (not a Unity Web Player file)

OK

Yet when i run the file straight through Unity it works fine. I even went so far as to resave it as a Web file and nadda.

on November 20, 2010

Flimgoblin

For anyone else who gets the problem @Houndie had: If you're using IIS try adding the mime type for .unity3d files to the configuration (it wasn't allowing the file to be served by default, all credit to finding this out to @Houndie :))

on November 21, 2010

Overhill

Thanks for the previous answer. Now the application is working just fine inside facebook. but...

Now everytime I enter the app in facebook it gives me this message on top of the application while the app itself is running nicely under this message.

Warning: filegetcontents() [function.file-get-contents]: SSL: fatal protocol error in /myURL/authorise.php on line 69

When I refresh the page the warning message goes away and the application runs nicely... strange I would say.

On a friend's computer it makes the same but gives two similar messages on top of the app:

Warning: filegetcontents() [function.file-get-contents]: SSL: fatal protocol error in /myURL/authorise.php on line 39 Warning: filegetcontents() [function.file-get-contents]: SSL: fatal protocol error in /myURL/authorise.php on line 69

Do you have any idea what is this about?

on November 24, 2010

Flimgoblin

Strange, it could be a certificate problem or it could be an IIS issue (see [filegetcontents][1])

It must still be returning the data OK though, otherwise you'd not be logged into the application. If you try changing lines 39 and 69 to have @<a href="/users/file_get_contents" class="mention">file_get_contents</a> instead of file_get_contents that should suppress the errors.

Alternatively add: error_reporting(0); to the top of config.php - just below the line with `

on November 24, 2010

Flimgoblin

Hmm, last comment went a bit strange.

Should change it from: file_get_contents to @<a href="/users/file_get_contents" class="mention">file_get_contents</a>

or add error_reporting(0);

to the config.php inside the PHP tags

on November 24, 2010

Flimgoblin

This thing needs an edit button :p

Add an @ (at) sign to the front of the function name :p don't add a link in like the WYSIWYG is doing to my comment...

on November 24, 2010

Overhill

Okay I changed filegetcontents to &#64;filegetcontentsOn both lines 39(to be accurate the word "filegetcontents" was on line 38) and 69. And it seems to work! Thanks again. And yeah an edit button for this forum/commenting thingy is a must.

on November 24, 2010

Overhill

okay... it didnt show the @ as I wanted and didnt make the text as it shows on that preview below the text. Come on... :D

on November 24, 2010

Lgrant

I would really like to see some more documentation on the supported function methods and callback methods before I shell out $75 for this. The demo preview doesn't help much...I don't want to send a sphere to all my friends just to see how it works. And I really need to know how much of the Graph API is accessible.

Thanks,

Lynn Grant Cross Design Group LTD

on December 10, 2010

Flimgoblin

The prefab will allow you to access anything you would like through the open graph. The default setup only asks the user for a few permissions so that it can post on their wall/their friends walls for gifts, so you'd need to edit the prefab configuration to extend the permissions. There are also some helper/wrapper methods which make some of the more common requests quicker to put together, but it's not too much of a stretch to pull in just about any sort of object exposed by the Graph API.

If you have a specific example or query of something you're looking to do please send me a message via the contact form and I'll let you know if the prefab supports it.

on December 12, 2010

Lgrant

How do you handle the facebook permission screen? Do you bring up a regular browser window for that?

on December 16, 2010

Flimgoblin

Yeah, it's a redirect to Facebook's permission dialog (how it has to be for oauth) - same as with any other facebook canvas app (this prefab is only for Unity running as a facebook canvas app i.e. on apps.facebook.com/something - not for standalone Unity games or iPhone).

on December 16, 2010

Daslolo

The example is not working look http://screencast.com/t/TV7uuta0

on December 29, 2010

Flimgoblin

Thanks for taking the time to record that @Daslolo - not sure why that's happening for you, even if you had a Facebook account with no friends it should show a "Loading..." message and then an error.

Can you tell me which operating system (Windows/Mac and which version?) and browser (Firefox/Chrome/IE again which version?) you are using and I'll see if I can reproduce the problem. Also if you know which version of the Unity plugin you have? (Just go to http://unity3d.com/webplayer/version/ )

Thanks, Flimgoblin

on December 30, 2010

Tornadotwins

Updated!

New Features include:

Prefab now includes both C# and Javascript code! Extended "permissions example" Safari click fix - work around for Safari third party cookie restrictions.

Thanks Fraser for this excellent product! -TornadoTwins

on January 11, 2011

Themisbrink

I have this error when i try to see the example app from inside facebook

{ "error": { "type": "OAuthException", "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration." } }

What am i doing wrong?

on August 17, 2011

Flimgoblin

@themisbrink Looks like some files have gone missing on the server, have contacted the Gameprefabs support folks, hopefully have this sorted soon.

on August 17, 2011

Benjamin

Hello, we seem to be getting a problem with this on facebook - testing it on facebook is tricky but when attempting to get the user's info it is returning a hashtable of only one key, instead of one of the required info!

on October 11, 2011

Flimgoblin

@benjamin Can you message me (via the contact form) a link to your app please? I'll take a look.

on October 11, 2011

Cheapdevotion

@Flimgoblin After about 15 minutes, none of the facebook graph calls seem to work anymore. I assume this is probably an expiring token issue - any ideas (or suggestions on how to debug)?

on October 20, 2011

Flimgoblin

@Cheapdevotion are you running multiple windows/sessions connected to the same facebook account? apparently logging out of one can cause all the sessions to be disconnected (though Facebook will eventually demand you login again). 15 minutes does seem a very short time for the session key to time out, but you never know...

For debugging you can throw some Debug.Log() calls on the call.response (or call.text) and check the webplayer logs: http://unity3d.com/support/documentation/Manual/Web%20Player%20Debugging.html

Alternatively, I often use Firebug plugin for Firefox which if you activate and use the "Net" tab you can see the POST calls being sent from the Unity plugin to your server PHP and see the responses its receiving.

Failing that if you can use the contact form to send me a link to your app I can take a look and see if I can tell what's going wrong. Alternatively if you are able to reproduce the problem on the example app let me know what steps you took (plus which browser/operating system you're using in case that's affecting it).

Thanks, Flimgoblin

on October 20, 2011

Benjamin

@Flimgoblin

I found what the initial callback.php is returning: "Error: authorise fail". We actually not long ago had a version uploaded and working perfectly, until a few days later when it stopped working and started returning that message, apparently without any changes to anything. The app isn't publically available right now to see. But any idea what might be causing that issue? (It gets the same error with just the example scene, and after reconfiguring and reuploading everything)

on November 23, 2011

Flimgoblin

@Benjamin Can you check that your PHP install has sessions (and in particular cookie-based sessions) enabled?

on November 24, 2011

Proxybyte

Does this api allow me to get a list of the users friends?

on December 14, 2011

Flimgoblin

@Proxybyte it does indeed.

on December 14, 2011

Blowfishstudios

Hi @Flimgoblin, I just purchased the plugin and am having the same issues as another poster.

I assume I am missing some files too. What is the best way to get this resolved?

Cheers,Ben.

"{ "error": { "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.", "type": "OAuthException" } }"

on January 4, 2012

Flimgoblin

@blowfishstudios I'm assuming you're the fellow who got in touch via email too? If so, sorted :) if not, send me a contact message via the form please.

on January 5, 2012

Shadowfork

Does this work with the score/achievements graph api feature... and do you have a sample of this implementation in your project?

on March 23, 2012

Flimgoblin

@shadowfork There's no specific support for achievements yet. You'll be able to get the data out using the prefab (it handles the authentication and has methods to allow you to get anything from the graph API for a user) but you'd have to write some code on top to handle the achievements specifically.

on March 24, 2012