Something I’ve been struggling with for my current game is the facebook integration – I’ve hit way more roadblocks than I should’ve done due to bugs or undocumented permission requirements.

Since my project uses Unity as a frontend, and Playfab as it’s backend, my starting point was this useful guide https://api.playfab.com/docs/tutorials/landing-players/facebook-unity

All of my problems were to do with the Facebook api though.
I initially used the latest facebook api from https://developers.facebook.com/docs/unity/ which was 7.11.0.

Installing this plugin wouldn’t work out of the box, as it creates a PlayServicesResolver folder that attempts to install some google play shenanigans behind your back.  Needless to say, this process failed to complete correctly with an “android gradle failed to fetch dependencies” error, and after some troubleshooting found that you had to go to your android sdk manager (which you can find in your Unity Edit->Preferences->External Tools menu) and make sure Google Play services, Google Repository, and Android SDK Build-tools were installed.

THEN I had an error about JAVA_HOME being defined, so I had to manually set a JAVA_HOME system variable to be my Java SDK bin directory (Luckily I already had a java sdk installed).

I also had to install openssl at some point in the facebook config process, and put that in my path so as to use cmd to generate a key.

After that madness, I had to follow the steps to:

  1. Create a Facebook app ID
  2. Add the “Product” of Facebook login
  3. Setup all the toggles I might need in the different Facebook config pages
  4. Copy the App ID and App Name into Unity
  5. The openSSL step…

I followed the example of how to do a facebook login, and it seemed to work in the editor (though it gives you a weird dialog and needs a special user key for login, not a real login), but you can skip the manual fuss by calling an editor auto-login step after the FB.LogInWithReadPermissions line:

https://gist.github.com/gkngkc/9d971afbf4a73e392bde45df46b7fb7a

Now anyway, this was working and I could login using the editor, but when I tried making a WebGL build…


404: SDK.js for Facebook SDK WebGL. from Unity3D

Great, I had to downgrade my Facebook SDK version, bloody hell, well this didn’t take too long (though fiddly as you have to remove both folders that got imported), but it took a while to find this reddit thread.

 

Now it was plain sailing right?  Wrong, because the Facebook login popup will auto-hide itself under Chrome, so it won’t actually work properly on any self-hosted web-page.  I still haven’t found a workaround for this, but the problem goes away if you add your app as a “Facebook Web Game” on the config site and run your game through the apps.facebook.com domain.  I had some errors in the facebook system when I was setting this up (the name selection wouldn’t refresh, so it said the name was taken when it wasn’t, and errored when I tried to continue), but generally this bit worked, and my game is now hosted by Facebook.

Something I tried to do before putting the game directly on facebook was to use the invitable_friends api to implement my “invite-a-friend” screen.  This will just error with an obscure message unless your game HAS an app.facebook.com version, so watch out for that.  I didn’t realise at first, so I changed to use Game Requests, which seems to be the modern way of doing these style of invites.

The latest thing to catch me out was these Game Requests.
The first unmentioned gotcha was this: https://stackoverflow.com/questions/29393865/facebook-android-sdk-game-request-dialog-shows-game-requests-are-only-available but simple to fix.

After that, the game would pop-up with a friend list, allow me to send a game request to them, then return as if everything was working.  Checking the target Facebook page showed no notification or any message.  What gives?  Well after much head wrangling and testing using the Graph API page; bear in mind it has to be a post, and the message should look like:

%userid%/apprequests?action_type=INVITE&data=data&message=message

I found out that the target account has to be added to your app’s config as a developer or tester.  It’s the first time I realised there was even a config page for such a thing, as it never had been mentioned before in any tutorials.  Oh well, after adding them as testers, they could then see the invites (though only in the game activity screen https://www.facebook.com/games/activity) and click them to go to the facebook game page!  Yey!  Only one afternoon wasted!

I’m still not sure why these messages don’t show an error if the user isn’t on the project, and I don’t know why the messages are filtered into only the activity screen, but at least I can work now.

 

Tune in next time to see what undocumented problems I encounter next 🙂

 

I hope this helps someone save a few hours,

Duncan

2 Comments

  1. Oleksiy

    All things in the first part (JAVA HOME, Google Play services, Google Repository, and Android SDK Build-tools) you would need anyway to make Android builds from Unity, it is not bound to FB SDK.
    openSSL is pretty easy to install, although I’d wish they had it mentioned somewhere with clear instructions on how to get it working

    Anyway, never tried to build it for WebGL with it. Thanks for sharing your experience!

    • DuncanS

      That might seem reasonable, but I had been happily making Android builds of my game before starting the Facebook version – I think the Facebook SDK might have required a specific version of those tools, and that’s why I needed to install more stuff? I think Unity will do more for you behind the scenes to make Android setup as easy as possible.

Comments are closed.