Facebook AppRequest handle on unity3d game

这一生的挚爱 提交于 2020-01-01 14:20:12

问题


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:


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:

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!



来源:https://stackoverflow.com/questions/18656932/facebook-apprequest-handle-on-unity3d-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!