Facebook Instant Game - Invite friends and Challenge

#1

Hello,

I am trying to implement the invite and challenge friends functionality. I’ve read on this forum that this should be done via the “fbinstant.choose_context”. So I implemented the method, uploaded the game and I am now testing on Facebook.

When the user presses the button, which calls this function, the user sees the following:


So all seems to be good here. When the invite is sent, Facebook nicely tells me that I have started a game with friend X in Messenger at the top of the game. However, the invite/challenge is never sent in the Messenger. So no body sees any of the invites/challenges.

The code I’ve written to achieve this looks like this (sharing works fine by the way!):

    if message.intent == fbinstant.SHARE_INTENT_SHARE then
			local im = sys.load_resource("/fish_game/assets/marketing/share_img_base64.json")

			local payload = 
			{
				["intent"] = message.intent,
				["image"] = im,
				["text"] = message.text
			}

			payload = rxijson.encode(payload)

			fbinstant.share(payload, function(self, success)
				print("was it a success?")
				print(success)
			end)
		elseif message.intent == fbinstant.SHARE_INTENT_INVITE then
			fbinstant.choose_context(nil, function(self, id, type)
				print("chose a context....INVITE!")
				print(id)
				print(type)
			end)
		elseif message.intent == fbinstant.SHARE_INTENT_CHALLENGE then
			fbinstant.choose_context(nil, function(self, id, type)
				print("chose a context....CHALLENGE!")
				print(id)
				print(type)
			end)
		end

When I look at the browser console, I do not see the print messages, by the way. I was wondering if I am doing this correctly on the Defold side.

Thanks!

1 Like

#2

Are you creating a debug build? Release builds will not show any output. Can you add a print() right before calling fbinstant.choose_context() as well?

0 Likes

#3

Oh, that’s right…I am not using a debug build. But wasn’t the build supposed to be a “Release” build in order for the facebook functionality to work?

0 Likes

#4

Nope. Not a requirement while testing. But to get the game as small as possible it should be a release build (and with anything from the engine you don’t need also removed).

0 Likes

#5

I tried it. It looks like the code returns a success:
image

I get the context id and type. I’ve tried it on multiple devices and other people have tried it as well.

Full code:

What could be the issue here?

0 Likes

#6

Ok, so that’s good. The code is executed and there is no crash. But you are not doing anything once you have switched context.

By calling choose_context() you “open a native dialog that allows the player to select which conversation they want to change to”. (https://developers.facebook.com/docs/games/instant-games/guides/play-friends#context)

So after you switched context to a conversation with a friend you either need to resume an ongoing game or start a new one and then call fbinstant.update() with a game update payload (https://developers.facebook.com/docs/games/instant-games/sdk/fbinstant6.3#customupdatepayload). This will show up in the conversation.

0 Likes

#7

So I tried that but still nothing.

The updated code:

What’s interesting here is that after the invite is sent, it shows the temporary notification pop-up on the top of the game screen (like it did before), but this time “print(“Succesfully updated the content for INVITE!”)” is never called. So fbinstant.update seems to fail if uploaded to facebook. It does however work if I launch the game from the editor by building it:
image

This is the fbapp-config.json file:

0 Likes

#8

The documentation for fbinstant.update() states that the payload must be JSON encoded. You’re
sending a table.

I’m surprised you didn’t get an error though…

2 Likes

#9

Yes, you are absolutely correct. This fixed the issue.

Thank you very much!

For anyone else wondering how I encoded it to JSON, have a look at my code above:
payload = rxijson.encode(payload).

1 Like