Facebook AppRequest handle on unity3d game

5.5k views Asked by At

I am trying to make a game in Unity3D with new facebook unity sdk. I am able to send an AppRequest to the friends in my list. But my doubt is, after my friends has downloaded the same game, how can I communicate with friends using the AppRequest.

For eg. If I am sending a "Life" to the friend, my friend should see a "Life" sent from me in his game. his "Life" counter should get incremented by 1 (life++). Same thing with "Ammo" can be done.

  1. Sender : How to differentiate the "Life request" and "Ammo Request".
  2. Receiver : In game, how to get that request and differentiate it, so that "Life" or "Ammo" counters gets incrementation.
1

There are 1 answers

9
aaron On BEST ANSWER

You have two options:

  • when an app request is created you always get a unique id back, which you can use to tie back to what type it is via a data tracking system (e.g. Parse)
  • when you call FB.AppRequest you can pass in a string as the 'data' parameter which will subsequently be returned to you when you fetch a user's app requests. (e.g. FB.API("/me/apprequests", YourCb);)

One other thing to pay attention to is if a player comes to your game via an app request, which you may want to respond to or notify them of. For example on Canvas: - Bobby McGee visits https://apps.facebook.com/friendsmashunity, sends me a request via FB.AppRequest. the return value of that call will be something like:

{ "request": "467375710036144", "to": [ "my_user_id" ] }

Then I see a notification like this: request notification

When I click on this link it opens up your game with the following parameters (you can see request_ids is one of them) - https://apps.facebook.com/friendsmashunity/?fb_source=notification&request_ids=467375710036144&ref=notif&app_request_type=user_to_user&notif_t=app_request

You can get the 'data' from an appid by calling FB.API:

  • call FB.AppRequest(...,data="life") => request id = 1234
  • later, a player visits your game with the request id 1234
  • you call FB.API("/1234") : the resulting JSON string will have a field data="life"

Hope this helps, and thanks for trying the SDK!