RTM icon indicating copy to clipboard operation
RTM copied to clipboard

How to get it or generate RTM Token?

Open AKK-Tech opened this issue 3 years ago • 6 comments

Could you please show me how to generate an RTM token or how to get it? When I log in with the application, it always responds "LOGIN_ERR_INVALID_TOKEN".

AKK-Tech avatar Jan 12 '22 08:01 AKK-Tech

See the doc: https://docs.agora.io/en/AgoraPlatform/get_appid_token?platform=AllPlatforms#generate-an-rtm-token

yamasite avatar Jan 12 '22 09:01 yamasite

I am adding temp token then also giving error of "LOGIN_ERR_INVALID_TOKEN" , as i am integrating Live chat Followed this Code : https://github.com/AgoraIO/RTM/tree/master/Agora-RTM-Tutorial-Android still getting "LOGIN_ERR_INVALID_TOKEN"

Afaquejaya avatar Mar 10 '22 05:03 Afaquejaya

As you can see:

/**
     * API CALL: login RTM server
     */
    private void doLogin() {
        mIsInChat = true;
        mRtmClient.login(null, mUserId, new ResultCallback<Void>() {
            @Override
            public void onSuccess(Void responseInfo) {
                Log.i(TAG, "login success");
                runOnUiThread(() -> {
                    Intent intent = new Intent(LoginActivity.this, SelectionActivity.class);
                    intent.putExtra(MessageUtil.INTENT_EXTRA_USER_ID, mUserId);
                    startActivity(intent);
                });
            }

            @Override
            public void onFailure(ErrorInfo errorInfo) {
                Log.i(TAG, "login failed: " + errorInfo.getErrorCode());
                runOnUiThread(() -> {
                    mLoginBtn.setEnabled(true);
                    mIsInChat = false;
                    showToast(getString(R.string.login_failed));
                });
            }
        });
    }

The token is hardcoded to null. If your Agora project enables tokens, this project will fail. You can update null with your token.

yamasite avatar Mar 10 '22 07:03 yamasite

As you can see:

/**
     * API CALL: login RTM server
     */
    private void doLogin() {
        mIsInChat = true;
        mRtmClient.login(null, mUserId, new ResultCallback<Void>() {
            @Override
            public void onSuccess(Void responseInfo) {
                Log.i(TAG, "login success");
                runOnUiThread(() -> {
                    Intent intent = new Intent(LoginActivity.this, SelectionActivity.class);
                    intent.putExtra(MessageUtil.INTENT_EXTRA_USER_ID, mUserId);
                    startActivity(intent);
                });
            }

            @Override
            public void onFailure(ErrorInfo errorInfo) {
                Log.i(TAG, "login failed: " + errorInfo.getErrorCode());
                runOnUiThread(() -> {
                    mLoginBtn.setEnabled(true);
                    mIsInChat = false;
                    showToast(getString(R.string.login_failed));
                });
            }
        });
    }

The token is hardcoded to null. If your Agora project enables tokens, this project will fail. You can update null with your token.

Thanks Alot it worked perfectly fine now 👍 , but how to check chatting functionality (Peer to peer & Channel Message) as I had install app in two devices and used sam temp token and set channel name as userA , when login with Account name : userA , but when login in other phone with userB then login fail , and when login with userA then it success, but how can I chat with my self , that not possible , how to login with Account name : userB so that I can test chatting functionality.

Afaquejaya avatar Mar 10 '22 09:03 Afaquejaya

That's the tricky part. UserA and UserB have different tokens.

https://docs.agora.io/en/AgoraPlatform/get_appid_token?platform=AllPlatforms

image

yamasite avatar Mar 10 '22 09:03 yamasite

wow.. means creating API to get tokens for all different users is a must it cant work with only temp token...!

Afaquejaya avatar Mar 10 '22 10:03 Afaquejaya