Facebook Instant Games
QuestEngine is a ready-made backend for HTML5 games on Facebook and Messenger. It covers sign-in that works with Zero Permissions, daily challenges with streaks, async duels you share in a chat, friend leaderboards from connected players, and Meta's data deletion requirements. It has the same player accounts, economy and live ops as mobile games, with no server of your own to run.
This guide follows the order of calls an Instant Game makes. The API reference has every field.
Before you start
- Add the game in the console, then open Game settings → Player accounts:
- tick Facebook Instant Games under sign-in methods;
- under Facebook, enter the App ID and paste the App secret (it is stored encrypted and never shown again);
- under Web games, tick Daily challenges and/or Async duels;
- set Delete inactive players after to the period your privacy policy promises, for example 183 days.
- Allow the API host in your game's network settings if you restrict them:
https://questengine.eu. - Every call sends the game's public client key,
X-Game-Key: qe_pk_…(console: API & SDKs). Player calls also sendAuthorization: Bearer <token>.
Daily challenges and duels also need the web-games features switched on for the QuestEngine server: QE_WEB_GAMES and the QE_FEATURE_* flags.
1. Sign in
Instant Games have no Facebook Login. The player is identified by a signature Meta makes with your app secret:
await FBInstant.initializeAsync();
const nonce = crypto.randomUUID();
const signed = await FBInstant.player.getSignedPlayerInfoAsync(nonce);
let signedAsid = null;
try { signedAsid = (await FBInstant.player.getSignedASIDAsync())?.getSignature() ?? null; } catch {}
const res = await fetch('https://questengine.eu/api/v1/auth/facebook-instant', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Game-Key': CLIENT_KEY },
body: JSON.stringify({
signature: signed.getSignature(),
request_payload: nonce,
signed_asid: signedAsid, // leave out when there is none
display_name: FBInstant.player.getName(),
platform: 'facebook_instant',
locale: FBInstant.getLocale(),
}),
});
const { data } = await res.json(); // data.token, data.player.id, data.player.instant_player_id
- QuestEngine checks the signature with your app secret (HMAC-SHA256). A signature is at most a day old and works once, so get a new one for each sign-in. The first sign-in creates the player (201); later ones sign the same player in (200).
player.idis the QuestEngine public ID, used in every other call.player.instant_player_idis the player's ownFBInstant.player.getID().signed_asidmatters for data deletion (see step 6). An invalid one fails the sign-in (401invalid_asid_signature), so only send what the SDK returned.- Tokens last the game's session length. Refresh with
POST /auth/refresh.
2. Friends from connected players
Under Zero Permissions there is no friends list and no access token, but getConnectedPlayersAsync() works. Send those IDs after sign-in and whenever you refresh them:
const connected = await FBInstant.player.getConnectedPlayersAsync();
await api('POST', '/friends/facebook-instant', { player_ids: connected.map(p => p.getID()).slice(0, 200) });
// → { connected: 2, players: [{ id, display_name, instant_player_id, … }] }
- Each import replaces the previous list. IDs nobody signed in with are ignored.
- The response maps each match's public
idto itsinstant_player_id, so you can match rows from the rest of the API. - Meta doesn't sign these IDs, so a connection is one-way: you see those players on your friends leaderboards, and they see you only if their game reports you too. It doesn't create a friendship, and nothing is sent to them.
3. Leaderboards
Create boards in the console (Leaderboards). Set the lowest and highest accepted score, because these scores come from the game.
await api('POST', '/leaderboards/daily/scores', { score: 1240 });
const world = await api('GET', '/leaderboards/daily'); // public: id and display_name only
const friends = await api('GET', '/leaderboards/daily/friends'); // you + friends + connected players
const me = await api('GET', '/leaderboards/daily/me?range=5'); // your rank and neighbours
On /friends and /me, every player also has instant_player_id for you, your friends and connected players (null for others). Use it to highlight "You" and friends. World boards never show Instant IDs.
4. Daily challenges
Create a channel in the console (Live ops → Daily challenges). Everyone gets the same seed, or the same questions, each day:
const day = await api('GET', '/daily/huddle');
// day.period_key "2026-11-20", day.seed, day.items (server-scored channels), day.streak, day.submitted
// … build the puzzle from day.seed and play …
await api('POST', '/daily/huddle/results', { period_key: day.period_key, score: 1240, duration_ms: 48000 });
- Open the challenge when the player starts playing. The first
GETof a day starts the player's round clock on the server. To show the streak or a "played today" badge at launch, useGET /daily/huddle?peek=true: the same answer without the seed and questions, and the clock doesn't start. - Send the
period_keyyou were given. For a few hours after midnight (the grace window), a late finish still counts for its own day. - Who scores it:
- seed channels: the game sends
score(up to the channel's maximum). - server-scored channels: the game sends
answers: [{ id, choice, time_ms }], and QuestEngine scores them. Answers slower than the real time are refused, and a round finished long after its time limits scores 0.
- seed channels: the game sends
- Streaks: one result a day keeps the streak. Freezes cover a missed day.
- Leaderboard: results can post to a leaderboard automatically, in the period of their own day.
- Shortest believable round: a channel can set one. Faster results are refused (422
too_fast).
5. Async duels
Import a question pack in the console (Live ops → Question packs). Packs are versioned JSON:
{ "code": "spar-en-general", "name": "General knowledge", "version": "v1", "locale": "en",
"round_count": 5, "time_limit_ms": 12000, "scoring": "authoritative",
"items": [{ "id": "q1", "prompt": "…", "choices": ["…", "…", "…", "…"], "correct": 2 }] }
Challenging someone. Pick one of:
- an open invite to share in the chat (no opponent);
- a connected player by Instant ID:
opponent_platform: { provider: 'facebook_instant', id }; - a player by public ID:
opponent_player_id; mode: 'ghost', to replay someone's earlier run.
const duel = await api('POST', '/duels', { content_pack: 'spar-en-general', context_id: FBInstant.context.getID() });
// share duel.invite_code with FBInstant.shareAsync / updateAsync; the challenger plays right away:
await api('POST', `/duels/${duel.id}/submit`, { answers: [{ id: 'q7', choice: 2, time_ms: 3400 }, /* … */] });
// the friend opens the link:
const found = await api('GET', `/duels/invite/${code}`);
await api('POST', `/duels/${found.id}/accept`);
await api('POST', `/duels/${found.id}/submit`, { answers: [/* … */] });
// → status "completed", winner_player_id, scores
How a duel runs:
- Scoring: questions are scored on the server. Each correct answer within the question's time limit is worth 100. The correct answers are shown only to players who have played, once the duel is over.
- Expiry: duels expire after 48 hours. If the opponent accepted but only one player played, that player wins. An invite nobody accepted just ends.
- Afterwards: a player can forfeit, rematch (
POST /duels/{id}/rematch) or check the record against an opponent (GET /duels/head-to-head/{public_id}). - Webhooks: if you set them, your server hears
duel.created,duel.accepted,duel.submitted,duel.resolved,duel.expired,duel.forfeitedandduel.rematch. - Packs: players see the answers after each duel, so keep packs large (100+ questions). Give a server-scored daily challenge a pack of its own.
6. Data deletion
Meta requires a way for players to delete their data. QuestEngine gives you three:
- In the game. Add a Delete my data button that calls
DELETE /mewith{ "confirm": true }. The player and their data are deleted at once. - Meta's Data Deletion Callback. In the App Dashboard, open Settings → Basic → User data deletion and set the callback URL:
When someone removes your game from Facebook, Meta posts a signed request. QuestEngine verifies it with your app secret, deletes the matching players and answers with a confirmation code and a status page. Meta names people by their app-scoped ID (ASID), so this finds only players whose game senthttps://questengine.eu/api/v1/facebook/data-deletion/<your app ID>signed_asidat sign-in. Meta doesn't give every Instant Games player one, which is why the in-game button matters. - The console. Players → Delete player, for requests that reach you by email.
All three delete the same things: progress, scores, streaks, duels, saves and friends. Purchases are kept without the link to the player for seven years, because accounting law requires it. Players who stop playing are deleted automatically after the period set in Game settings.
Errors
Every error has the same shape: { "error": { "code": "…", "message": "…", "details": { … } } }. Codes you'll meet in Instant Games:
| Code | Meaning |
|---|---|
invalid_signature, signature_expired, signature_replayed |
Get a fresh getSignedPlayerInfoAsync() and sign in again |
feature_disabled |
Daily challenges or duels aren't on for this game or server |
round_not_started, too_fast, timing_implausible |
Daily or duel timing checks (see above) |
period_closed |
That day no longer takes results |
duel_expired, duel_not_in_progress, already_submitted |
The duel moved on; reload it |
rate_limited |
Slow down, then retry after a moment |
Next: the API reference for every endpoint and field, and the SDK guides if you also ship to mobile.