Open APIs
Handle user authentication and authorization through silent login and scope-based permission requests, and provide access to the open data context for reading user cloud storage and relational data.
TTMinis.game.login(opts)
Initiates a silent login for the mini game.
Parameters
Field | Type | Description | Required |
|
| The callback function called when the API call succeeds | No |
|
| The callback function called when the API call fails | No |
|
| The callback function called when the API call ends, regardless of success or failure | No |
Success callback parameters
Field | Type | Description |
|
| The login authorization code. Send this code to the backend server in exchange for |
Example
TTMinis.game.login({
success: (result) => {
// The user has logged in and authorized the application
// Send the code to the backend in exchange for open_id, access_token, etc.
let code = result.code;
},
fail: (error) => {
// Other errors or deauthorization; code is null
},
complete: () => {
// Triggered for both success and failure
}
});TTMinis.game.authorize(opts)
Initiates the authorization flow for the mini game.
Parameters
Field | Type | Description | Required |
|
| The scope of the permission to request. See the scope list for details. | Yes |
|
| The callback function called when the API call succeeds | No |
|
| The callback function called when the API call fails | No |
|
| The callback function called when the API call ends, regardless of success or failure | No |
Success callback parameters
Field | Type | Description |
|
| The authorization code. Send this code to the backend server in exchange for |
Example
TTMinis.game.authorize({
scope: 'user.info.basic',
success: (result) => {
// The user has logged in and authorized the application
// Send the code to the backend in exchange for open_id, access_token, etc.
let code = result.code;
},
fail: (error) => {
// Other errors or deauthorization; code is null
},
complete: () => {
// Triggered for both success and failure
}
});TTMinis.game.getOpenDataContext()
Gets the open data context.
Returns
An OpenDataContext object for interacting with the open data domain.
Example
const openDataContext = TTMinis.game.getOpenDataContext()OpenDataContext
The open data context object, which provides a shared canvas and messaging between the main domain and the open data domain.
Properties
Field | Type | Description |
|
| The shared canvas between the open data domain and the main domain |
OpenDataContext.postMessage(message)
Sends a message to the open data domain.
Parameters
Field | Type | Description | Required |
|
| The message to send. Values of keys in the message and nested objects can only be primitive types: | Yes |
Example
const openDataContext = TTMinis.game.getOpenDataContext()
openDataContext.postMessage({
type: 'updateScore',
score: 100
})TTMinis.game.setUserCloudStorage(opts)
Writes user-managed cloud storage data. Supports writing multiple key-value pairs at once.
Parameters
Field | Type | Description | Required |
|
| The list of key-value data to write | Yes |
|
| The callback function called when the API call succeeds | No |
|
| The callback function called when the API call fails | No |
|
| The callback function called when the API call ends, regardless of success or failure | No |
KVData
Field | Type | Description |
|
| The key of the data entry |
|
| The value of the data entry |
Example
TTMinis.game.setUserCloudStorage({
KVDataList: [{
key: 'score',
value: '100'
}, {
key: 'level',
value: '5'
}],
success: () => {
console.log('Cloud storage updated')
}
})TTMinis.game.removeUserCloudStorage(opts)
Deletes user-managed cloud storage data for the specified keys.
Parameters
Field | Type | Description | Required |
|
| The list of keys to delete | Yes |
|
| The callback function called when the API call succeeds | No |
|
| The callback function called when the API call fails | No |
|
| The callback function called when the API call ends, regardless of success or failure | No |
Example
TTMinis.game.removeUserCloudStorage({
KVDataList: ['score', 'level'],
success: () => {
console.log('Cloud storage entries removed')
}
})