Check if Facebook Instant API is available at runtime

#1

I have a game that works on Facebook Instant. I’d like to release it on web outside the Facebook Instant eco system keeping the same code base.

When I call:

fbinstant.initialize( on_intialize )

This message is shown in the browser console:

FBInstant inited undefined

But the callback (on_initialize) is never triggered inside the game.

What’s the best way of checking if the Facebook Instant API is unavailable? It would be good to get a “success false” response from fbinstant.initialize.

0 Likes

#2

Just mentioning that we put these extensions up on github to make it easy for our users to create pull requests :wink:

3 Likes

#3

I wish I had the skillz to do this one!

0 Likes

#4

Two ideas:

  1. The call to fbinstant.initailize() will return true/false depending on result. Use a return value of false to run it as a stand alone game.
  2. Check location.href using local url = html5.eval(“location.href”) and see if you’re launching from a Facebook url or something else.
0 Likes

#5

I like both options, but:

  1. fbinstant.initailize() doesn’t return anything when run outside Facebook. I can’t seem to wrap my head around the code to change it.
  2. I’m reluctant to do this, because I’d be relying on a domain name or URL that you have no control over and which might change over time (admittedly the “Facebook” domain IS probably quite safe…)
0 Likes

#6

Really? The callback doesn’t get invoked?

fbinstant.initialize(function(self, success)
    print(success)
end)

If you don’t get a callback then I’d consider that a bug. Please create a ticket and link it here.

Yes, I think that is safe to assume :slight_smile:

0 Likes

#7

Exactly. It triggers locally in the Defold player, and on Facebook, but not when published with “Build HTML5”.

0 Likes

#8

And, does the browser console log say anytihng?

0 Likes

#9

Yeah; “FBInstant inited undefined” (see first post).

0 Likes

#10

That printout is from this line

Is that the only printout in the console?
Could it be that the function doesn’t continue since the “Module._fbinstant_inited” is undefined?
If so, you could patch that in a pull request :slight_smile:

0 Likes

#11

Yeah, that’s the only relevant printout (meaning the game doesn’t crash, and continues). I’ve tried to change the code locally with, shall we say, minimal success. :slight_smile:

0 Likes

#12

Well, the Facebook Instant Games API doesn’t provide any functionality to check if run from within a Facebook context or not. And calling fbinstant.initializeAsync() simply does nothing and never returns as far as I have been able to test. The javascript promise never resolves and no error is thrown.

I see two options:

  1. Check the browser location and if it is not launched on Facebook you either ignore calling any FBInstant APIs or you mock all calls to them (there’s a mock.lua in the extension that can be used as a base maybe).
  2. Bundle two different versions. One version for Facebook Instant Games using the FBInstant API and one version where the API calls are removed or mocked.
1 Like

#13

Bummer. But thanks! I’m going down the URL route, against my better judgement. :slight_smile:

Edit: Heads up if you’re doing the same; this is (currently) the URL format for Facebook Instant game content:

https://apps-476224266222372.apps.fbsbx.com/instant-bundle/2329741583763987/2405086579579777/

It makes it a little trickier/more risky, because this domain/url might change.

0 Likes