Last Updated on : 2024-06-26 09:46:59download
The QR code login authorization feature allows your app to scan an authorization QR code and enables multiple devices to log in to the app with the same account. The devices can be central control devices, TV sets, or tablets.
In the following process, the app on the central control device must be included in the allowlist. Otherwise, an error message will be returned. For example, if the Smart Life app is used to scan the QR code of the SDK that is created on the Tuya Developer Platform and the app is not included in the allowlist, an error message is returned and the session expires.
The following table describes the steps in the process. Five API methods are used in this topic.
No. | Purpose | Description | API method |
---|---|---|---|
1 | Get the token | The device requests to get the token for authorization. | getQRCodeToken |
2 | Generate a QR code | Use the returned token to generate a QR code in a specific format.
|
– |
3 | Get the login status | Poll the server to get the authorization status. If the authorization is successful, the user information is returned and users are navigated to the app homepage for subsequent operations. Note: The polling interval time should not be less than 2 seconds per iteration. | QRCodeLogin |
4 | Scan the QR code | The app is used to scan and parse the QR code on the device and authorize the device. | – |
5 | Authorize login | Send the parsed QR code to the cloud to complete the authorization. | QRcodeAuth |
void getQRCodeToken(String countryCode, IGetQRCodeTokenCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . |
callback | The callback. |
Example
ThingHomeSdk.getUserInstance().getQRCodeToken("86", new IGetQRCodeTokenCallback() {
@Override
public void onSuccess(String token) {
}
@Override
public void onError(String code, String error) {
}
});
void QRCodeLogin(String countryCode, String token, ILoginCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . |
token | The token granted for login. |
callback | The callback. |
Example
ThingHomeSdk.getUserInstance().QRCodeLogin("86", "xxxx", new ILoginCallback() {
@Override
public void onSuccess(User user) {
if (user != null && !TextUtils.isEmpty(user.getSid())){
ThingHomeSdk.getUserInstance().loginSuccess(user);
// The value of `homeId` for the target device.
Object homeId = user.getExtras().get("homeId");
gotoHomePage();
}
}
@Override
public void onError(String code, String error) {
}
});
This method only applies to central control devices. The app is used to scan and parse the QR code on the device and authorize login to the device.
API description
void QRcodeAuth(String countryCode, long homeId, String token, IBooleanCallback callback);
Parameters
Parameter | Description |
---|---|
countryCode | The country code, such as 86 . |
homeId | The home ID. For more information, see Home Management. |
token | The token granted for login. |
callback | The callback. |
Example
ThingHomeSdk.getUserInstance().QRcodeAuth("86", mHomeId, getActivityToken(), new IBooleanCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback