This feature is no longer available for new submissions. This documentation is intended solely for developers with existing games.
Enable Cross Play between an Instant Game and the native version of that same game allows players to share features across versions of a game and pick up where they last left off in a game regardless of which version of the game that they were playing.
Other documentation for Cross Play:
After your native games is integrated with Facebook Login for Gaming, you will get back an access token for Gaming Graph Domain (the token starts with ‘GG’ prefix). With that token, you can access the following graph APIs offered by Cross Play.
GET graph.fb.gg/{user-id}?fields=instant_game_player_id
Requirements:
Response:
{ "id": "1234567890", "instant_game_player_id": "890123456" }
GET graph.fb.gg/{user-id}/ids_for_business
Requirements:
/{user-id}?field=instant_game_id
API instead.Response:
user_id_type
field.{ "data": [ { "app": { "name": "My Native Game", "id": "11223344" }, "user_id_type": "platform", "id": "890123456" }, { "app": { "name": "My Instant Game", "id": "44332211" }, "user_id_type": "instant_game", "id": "890654321" }, ] }
GET graph.fb.gg/{user-id}/data
Requirements:
Response:
{ "data": [ { "key": "achievements", "value": "[\"medal1\",\"medal2\",\"medal3\"]" }, { "key": "currentLife", "value": "300" }, ] }
POST graph.fb.gg/{user-id}/data
Requirements:
Payload:
curl -X POST https://graph.fb.gg/{user-id}/data -d "payload={currentLife:350}"
Response:
{ "success": true }
To access the new features and APIs from Instant Game SDK, you need to first import the Cross Play Beta version of Instant Game SDK in your game:
<script src="https://connect.facebook.net/en_US/fbinstant.beta-xplay.js"></script>
FBInstant.player.getASIDAsync(): Promise<void>
Requirements:
ids_for_business
Graph API instead./* * Performs a graph API Call and returns the result. * @param {string} path The graph API path to perform the request against. * @param {?string} method HTTP method that will be used for this request. GET * is the default if not specified. * @param {?Object} params Parameters that will be sent as part of the request. * @return {Promise} the result of the graph API call. */ FBInstant.graphApi.requestAsync( path: string, method: ?string, params: ?Object): Promise<Object>
Requirements:
FBInstant.graphApi.requestAsync('/me').then(response => { console.log(JSON.stringify(response)); });
FBInstant.canSwitchNativeGameAsync(): Promise<bool> FBInstant.switchNativeGameAsync(data?: ?Object): Promise<void>
Requirements:
canSwitchNativeGameAsync()
first and only prompt users for navigation if response is true.For this API to work the game needs to have their Android/iOS apps to use the same Facebook AppID and the native settings configured in the developer portal.
Android:
Payload:
import com.facebook.gamingservices.GamingPayload; @Override protected void onStart() { super.onStart(); // call this during onStart() so that it works for Cold Starts as well as // app switches when your app is already open. // NOTE: For Cloud Games, GamingPayload will be loaded internally when you call // CloudGameLoginHandler.init() GamingPayload.loadPayloadFromIntent(getIntent()); // Once the payload has been retrieved either from the Intent or From Cloud, // you can get the GameRequest ID and Payload using: Log.e(TAG, "Game Request ID: " + GamingPayload.getGameRequestID()); Log.e(TAG, "Payload: " + GamingPayload.getPayload()); // You can now redirect the User to the appropriate screen within your game to // complete the action they were invited to do. }
#import <FBSDKGamingServicesKit/FBSDKGamingServicesKit.h> #import "Console.h" @interface GamingPayloadDelegate : NSObject <FBSDKGamingPayloadDelegate> @end * GamingPayloadDelegate.m #import "GamingPayloadDelegate.h" @implementation GamingPayloadDelegate - (void)updatedURLContaining:(FBSDKGamingPayload *)payload { ConsoleLog(@"payload: %@", payload.payload); ConsoleLog(@"game request ID: %@", payload.gameRequestID); } @end
#import <FBSDKGamingServicesKit/FBSDKGamingServicesKit.h> #import "GamingPayloadDelegate.h" - (void)viewDidLoad { [super viewDidLoad]; self.payloadDelegate = [GamingPayloadDelegate new]; GamingServicesRegisterCells(self.tableView); FBSDKGamingPayloadObserver.shared.delegate = self.payloadDelegate; } - (void)viewWillDisappear:(BOOL)animated { FBSDKGamingPayloadObserver.shared.delegate = nil; }