You are on page 1of 3

A2U Notifications on Instant Games

Instant Games SDK Requirement


● Instant Game SDK 7.0 or newer

Instant Games SDK


requestAsync( )
Performs a graph API Call and returns the result.

Parameters
path string The graph API path to perform the request against.
method string? HTTP method that will be used for this request. GET is the default if not
specified.
params Object? Parameters that will be sent as part of the request.

Examples
FBInstant.graphApi.requestAsync('/me?fields=id,name')
.then(function(response) {
...
});

Returns Promise<Object> the result of the graph API call.

What about Access Token?

Access token will be embedded in the API call after users authenticate the game, so there is no
need to pass access token to this function.

A2U on Instant Games


There are at least 3 different scenarios:
● A2U to the current user on Instant Games
● A2U to a user who are not currently on Instant Games
● A2U to a friend of the current user on Instant Games

A2U to the current user on Instant Games?


Access token is embedded in the API call after users authenticate the game, sending A2U to the
current user on Instant Games is as simple as just calling:

FBInstant.graphApi.requestAsync('/me/notifications', 'POST', {

"href": "?gift_id=123",
"template": "You have people waiting to play with you, play now!"
}).then(result => console.log(result))

A2U to a user who are not currently on Instant Games


1. After users enter Instant Games, calling FBInstant.player.getASIDAsync() to get
the ASID of the current user, and also calling FBInstant.player.getID() to get
the Player ID of the current user.
2. Saving the mapping relationship <Player ID, ASID> to database
3. When you want to send A2U to a user, first looking up the user’s ASID in the above
mentioned map, and then calling POST /<ASID>/notifications endpoint on server
side with app access token
4. A2U sent!

A2U to a friend of the current user on Instant Games


1. One possible scenario is that you’ve called
FBInstant.player.getConnectedPlayersAsync() and rendered the friends list
of the current user, where user can choose to which friend to send A2U
a. Please note that only after users have granted user_friends permission can
getConnectedPlayer return the user’s friend list
2. The ID returned by FBInstant.player.getConnectedPlayersAsync() is Player
ID. When user picks a friend to send A2U, making a server request and look up users
ASID in the database
3. Once the ASID of the target friend is found, calling POST /<ASID>/notifications
endpoint on server side with app access token
4. A2U sent!

Relevant Documentations:
● https://developers.facebook.com/docs/games/build/legacy-web-games/gaming-
services/appnotifications
● https://developers.facebook.com/docs/graph-api/reference/user/notifications
Additional Guidelines:
● <PlayerID, ASID> mapping falls under the category of User Data as well, when
implementing data deletion callback, please also remove the mapping of the user who
triggers the data deletion request

You might also like