Unity Facebook (using Graph Api) example + documentation

Hey guys,

as you can read in the topic i am selling an Unity Facebook example + documentation for setting up your own Unity game in Facebook in less than 5 minutes.

For this purpose (and for some artist buddies) i set up http://www.polyload.com for selling our stuff a few weeks/month ago. It’s now in a kind of beta stage, so please feel free to contact me if you find bugs or strange behaviours.

Get it here: http://polyload.com

Features of the example i am providing with full source:

  • Display your facebook picture and name in your Unity3d webplayer app
  • Post to your wall by pushing a Unity GUI Button
  • Using new Facebook Graph API php-sdk (not the old Rest API)
  • Unity3d 3 compatible

You can preview the result here:

http://apps.facebook.com/unity_example/

To extend the example you just have to find the right Graph Api calls from here and insert them on the right spots in the example source:

http://developers.facebook.com/docs/api

Feel free to post your feedback! And tell me if sth. is unclear or doesn’t work oooor could be improved.

Thanks Merry Christmas,
Ethan

I might want to buy this for a school project. But before i do so, I have some questions:
Is it possible to invite friends?
Is it possible to send gifts?
Is it possible to run the scripts without having the webplayer in the facebook canvas page?
Im getting some issues in reading non english letters(im from Denmark), could that be fixed?
If we are going to buy it, and you make further development on it, would we be able to get the updates for free?

Beside all that I just want to tell that it’s a really awesome project you have been working:smile: I have been looking for something like this for a while.

Hi Qvist,

you can do everything what the Graph Api is capable of, just in the same way i loaded the userpicture or posted to your wall.
The example uses Unity’s WWW class to call Graph Api URLs or it’s own php scripts, which contain Graph Api stuff, too.
You don’t have to mind about the authorization and Graph Api setup - that’s already done. Just place your Graph Api calls.

Here is a simplified example how to get your own picture (the used Graph Api call is in bold):

// we get m_myFacebookUserId via external javascript functions from index.php
var www : WWW = new WWW ("[B]https://graph.facebook.com/" + m_myFacebookUserId + "/picture[/B]");
    
   // Wait for download to complete
  yield www;
    
  var newTextureFromWeb : Texture2D = www.texture; // here you get the picture as texture

You can find more Graph Api calls for all your needs here:
Graph API - Documentation - Meta for Developers

Hope this helped you :slight_smile:
Regards,
Ethan

Hi Ethan
Thanks for the quick response!
Then i want to hear about the letter issue. Can that be fixed? Need these letters: æøå.
I like coding in C#. I wont get some issues when using the Graph API?
These might be stupid questions, but i’m not into all unity stuff yet:smile:

Best Regards
Qvist

The letter stuff is just about the right charset. If you want to display those chars in html you have to find the right shortcut to the char (see this table: HTML 4.0 Latin-1 Entities). If you want to display such chars in Unity you have to pick the right charset in your codeeditor.

It works with C# or JavaScript, there’s no difference. :slight_smile:

Thanks for the answer:smile:

I will buy it in about a month or two:smile:

interesting aproach on that WWW.texture call… however I done it trough regular url… My API is little more complicated but works just right… nice work btw

cupsster: Thanks :wink:

Qvist: Great! I hope it will help you.

Hi Ethan,
I bought the package and it was super easy to implement.
I Just followed the instructions and got it all working in no time.
I’ll keep you posted as I make some progress on my game.
Thanks for putting it out there :wink:

Hi,
i started working on a fb app some months ago.
Some weeks ago i wanted to finish the app, port everything to the new fb api and then stumbled upon your handy little script. After 3 hours i had everything ported and working! Thanks for that! :slight_smile:

I can only recommend this to everyone interisted in connecting unity and facebook. It’s a great kick-start script :wink:

The only critique i have is that the php code could be a bit more organized. (Important variables are scattered over multiple files. One can easily change that himself though). At the end of the day the 18€ were very well worth it though.

A big timesaver, thanks!

Link to fb-app ported to the “new” api using ethan’s prefab: http://apps.facebook.com/messagemadness

thank you guys :slight_smile:

Hi guys,
Were you able to access any other features of the Graph API besides profile picture and name.
I’m trying to access photos or albums , but no luck so far.
Any idea how to do that?
Thanks,
E

Maybe you missed to get some more permissions at startup? In the example the app just asks for post-to-own-wall permissions.

That’s the part that I actually did figured out how to do. So I did ask for all the permission, just not sure how to write the functions to grab the photos.

hey eyal

sorry for the late answer :slight_smile:

I found a link which should help you:

I would guess it should work like this:

$photo = $fb->api('/98423808305'); // id of photo - see link above
echo '<img>'. $photo[data]['picture'] .'</img>'; // $photo[data]['picture'] should contain the link to the .jpg

maybe you have to leave the [data] away or sth (sorry, i cant test it atm).

hope this helps anyway,

cheers
ethan

Ethan, does this system work in a web player that is not a Facebook App? For instance, if the webplayer was running on my site, or kongregate etc… could I still allow my player to authenticate with FB and post to their wall?

Hi Sean sorry for the late reply,

unfortunately the facebook php-sdk always redirects to facebook, even if you call your url which is displayed in the facebook iframe.

Cheers
e

I am feeling kind of stupid. I’ve bought the package, followed the instructions, uploaded the app, but when I try to access it, the browser keeps loading in loop but never loads the app. Any idea of what may I did wrong?

Have anyone experienced the same problem? Ethan, can you give me some help, please?

Hey lima,

sorry i wasn’t available for some days. The problem is, that facebook changed something in the settings, which forces you to do the following:

  1. Go to your developer page “My Applications”
  2. Select your app and ‘Edit Settings’
  3. Advanced > Migrations > Enable the “OAuth 2.0 for Canvas (beta)”

Maybe you should also update the facebook php-sdk (the facebook.php in facebook/src):
https://github.com/facebook/php-sdk/
But this wasn’t necessary for my apps.

Please tell me if this worked for you. I just updated the package in the AssetStore.

Cheers
Ethan