How it works
- In the portal enter a frame address (https). It is the page of your game that opens in a frame on the app page in the catalog.
- Add the SDK to that page:
<script src="https://www.balktalk.net/sdk/v1.js"></script>
- Sign the member in and call the API:
await BalkTalk.ready()
const session = await BalkTalk.authorize({
clientId: 'YOUR_CLIENT_ID',
scopes: ['scores', 'activity'],
})
const me = await BalkTalk.api('/me')
console.log('Playing:', me.data.display_name)
The first time, BalkTalk asks the member for consent in its own window. After that authorize returns a token right away.
SDK
| Call | What it does |
|---|---|
BalkTalk.isEmbedded() |
true when the app runs in a frame on BalkTalk |
BalkTalk.ready() |
tells BalkTalk the app has loaded; returns { locale, theme, app } |
BalkTalk.authorize({ clientId, scopes }) |
sign-in without a redirect (PKCE); returns { accessToken, expiresAt, scopes } |
BalkTalk.requestCode({ scopes, codeChallenge }) |
only the sign-in code, for an app that exchanges it on its own server |
BalkTalk.api(path, { method, body }) |
a public API call; the token refreshes itself |
BalkTalk.share({ text }) |
the post window on the Network with your text (the share scope) |
BalkTalk.close() |
closes the frame |
Errors are Error objects with a code field: access_denied (the member denied), insufficient_scope, not_embedded (the app is not in a frame), timeout, and the public API codes.
The token lives only in the memory of the page. Do not store it in localStorage.
An app with a server
If you exchange the code for a token on your own server (client secret), take only the code in the browser:
const { code, redirectUri } = await BalkTalk.requestCode({
scopes: ['scores'],
codeChallenge: CHALLENGE_FROM_YOUR_SERVER,
})
// send code to your server; it calls https://www.balktalk.net/oauth/token with redirect_uri = redirectUri
In this flow redirect_uri is always your frame address. You do not have to add it to the redirect addresses.
Leaderboards
You create leaderboards in the portal (at most 5 per app). Each has a key, an order (a higher or a lower score is better) and a format (a number, or time in milliseconds).
const result = await BalkTalk.api('/boards/main/scores/me', {
method: 'PUT',
body: { score: 1200 },
})
if (result.improved) showNewRecord(result.data.rank)
const top = await BalkTalk.api('/boards/main/scores?limit=10')
Only the member's best score is kept. The leaderboard is also shown on your app page in the catalog.
The score is sent by your app and BalkTalk cannot verify it. If the ranking matters to you, compute and send the score from your server, not from the browser.
“Is playing …” in chats
While the frame is open, BalkTalk shows on its own that the member is using your app. If the app runs on your site, report it yourself once a minute (the activity scope):
await BalkTalk.api('/activity', { method: 'POST' })
Who sees it is up to the member, in their settings (Online status → Radio and games).
The frame
- The frame is isolated: it has no access to the BalkTalk page, cookies or the member's session. Everything goes through the SDK and the public API.
- The app cannot redirect the whole page or open new windows. Camera, microphone and location are not available.
- Full screen, sound and game controllers are allowed.
- The frame takes the width of the page. Build the game to work from 320 px wide and up, and with touch.
- The frame address must be https. While developing,
http://localhostworks, and only you and your testers see such an app. - Some browsers ask for permission to access the local network for
http://localhostin a frame, or block it. If the frame does not load, put the game on an https address while developing (for example through a tunnel).
An app on its own site
An app without a frame address is in the catalog with a link to its site. There it uses the regular sign in with BalkTalk.