Help Center/ Meeting/ Client SDK Reference/ Android SDK/ Typical Scenarios/ Scenario 3: Login Using an App ID
Updated on 2023-03-23 GMT+08:00

Scenario 3: Login Using an App ID

Description

If you have applied for an app ID, you can use the app ID to log in to Huawei Cloud Meeting, without entering an account and password.

If you have not logged in, you can only join created meetings.

Service Process

  1. Call an API.

    1. Create an AppIdAuthParam object.
      1. Set the unique ID of a third-party account.
      2. Set a random character string.
      3. Set signature information.
      4. ID of the enterprise to which the user belongs. This parameter is mandatory only in SP mode.
      5. Set the password expiration time.
      6. Set the nickname of the login account.
      7. Set the email address of the login account.
      8. Set the mobile number of the login account.
    2. Call the loginByAppid API to log in. The data in the preceding step is used as input parameters. The meeting server registers the user accordingly.

  2. Implement the callback.

    Process the result in the callback.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Create a login object.
AppIdAuthParam appIdAuthParam = new AppIdAuthParam();
// Set the signature expiration time. The value is a Unix timestamp, in seconds. If the value is 0, the signature will not expire.
appIdAuthParam.setExpireTime(1599618620);
// Set a random character string consisting of 32 to 64 characters.
appIdAuthParam.setNonce("hYLOWv69MIikVussTOucZOyWEMM1reDi");
// Set the ID of the enterprise to which the user belongs. This parameter is required only in the SP login scenario.
appIdAuthParam.setCorpId(123);
// Set the ID of the third-party account. The value is a string of 1 to 64 characters.
appIdAuthParam.setUserId("huawei123456");
// Set signature information.
appIdAuthParam.setSignature("198c3046dbdafa9d89ce917c5613c29fda855da2aa79f8f51f2871e88fdba91c");
// Set the user nickname.
appIdAuthParam.setUserName("huawei123455");
// Set the email address, which must meet the format requirements.
appIdAuthParam.setUserEmail("huawei123456@huawei.com");
// Set the mobile number, which must be in the correct format, for example, ^$|^[+]?[0-9]+$.
appIdAuthParam.setUserPhone("15900000000");
// Start to log in.
HWMSdk.getOpenApi(getActivity().getApplication()).loginByAppId(appIdAuthParam, new HwmCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                dismissLoading();
                dismiss();
                if (loginResult != null) {
                    DemoUtil.showToast("Login succeeded" + loginResult.getUserUuid());
                }else{
                    DemoUtil.showToast("Logged in");
                }
            }

            @Override
            public void onFailed(int retCode, String desc) {
                HwmContext.getInstance().runOnMainThread(() ->{
                    dismissLoading();
                    Error error = HWMBizSdk.getLoginApi().convertErrorCodeToUI(retCode);
                     DemoUtil.showToast("Login failed: "+ getLoginErrTips(error));
                    dismiss();
                });
            }
        });

Precautions

The loginByAppid API can be called only after HWMSdk.init is successfully called.