3

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.
henrywright
  • 10,070
  • 23
  • 89
  • 150
Nick
  • 1,035
  • 1
  • 11
  • 18

1 Answers1

3

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!

aaron
  • 1,746
  • 1
  • 13
  • 24
  • 1
    Hey @aaron Thank you so much for the reply. I got it what you trying to say. Just one doubt. On device (android or iOS), whenever request is received, how to trace that I have received the request so that I can call FB.API("/1234") and parse Json on receiver. – Nick Sep 07 '13 at 04:54
  • 1
    For eg. in TopEleven game, whenever we send any pack to a friend, all the receiver don't have to visit facebook on device. He just gets number notification inside the game menu. **Do I will have to keep on checking for the request using FB.API()?** **If not, then when to call FB.API()?** **How receiver will get the request_id in-game?** – Nick Sep 07 '13 at 05:15
  • 1
    Android has a uri as well, call getActivity().getIntent().getData() and it returns a Uri. you can then say intentUri.getQueryParameter("request_ids"); to get the request ids if it was started this way. (we don't support this directly in the FB Unity SDK. I don't think this is a common use case and wanted to keep things simple) – aaron Sep 07 '13 at 06:32
  • 1
    For your second question: I'm afraid we don't have subscriptions for app requests. but since they have to originate from within your own game you have the opportunity to implement your own push approach if you have a backend set up to do this (e.g. Parse let's you implement an afterSave function if that's what you're looking for). – aaron Sep 07 '13 at 06:44
  • 1
    So I will have to use JNI to add this additional functionality.. I guess..?? :( – Nick Sep 07 '13 at 06:44
  • 1
    I'm afraid so, I'm sorry for your frustration. My biggest goal for the Unity SDK is simplicity, and fetching all requests and showing them to the user in a game specific way seems to be the approach most developers have taken. That said, you're not the first person to ask for this, so I'm open to adding it. In the meantime something like this in your C# might work: AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject jo = jc.GetStatic("currentActivity"); jo.Call("getData",...); Not too tough, I hope, and sorry, again, for the frustration. – aaron Sep 07 '13 at 07:01
  • 1
    Thats fine.. As you suggested to use JNI. I will have to make new java class and import facebook SDK to it. Then use getActivity().getIntent().getData() like this [link](https://developers.facebook.com/docs/android/app-link-requests/) in the getData (). and call it through AndroidJavaObject. Right? Hope it will be added soon.. Cant wait to add this awesome SDK in my game. – Nick Sep 07 '13 at 07:53
  • 1
    that link is correct for getting the requests. Good luck, can't wait to try your game. – aaron Sep 08 '13 at 04:42
  • 1
    quick heads up we're releasing a new SDK next week to reveal the invoking URI. should be up by Wednesday: 4.3.3 – aaron Oct 14 '13 at 05:30