Agora.io token issue Android

Viewed 955

We are generating agora token from token server provided by agora but the token expires immmediately after the generation it throws DYNAMIC-KEY-EXPIRY with error code 109 and i have tried using onRequestToken() call back method provided in SDK below is the code snippet

override fun onRequestToken() {
            //this will be called when the token expires
            //so generate new token and renew the existing token
            runOnUiThread {
                regenerateToken()
            }
        }

and getting another token from server and renewing the token using mRtcEngine.renewToken(token) we have contacted agora team regarding this but unable to find the issue the token generated works sometimes,we have two account one is test account and other is main account when we use the one credentials it works for a day or so and after we need to change the credentials for every 2 days and the new generated token is expiring just after the generation So if any one faced the same issue and any help regarding this is appreciated

4 Answers

We are generating the token using agora token server and the time expiration is 3600

const { RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole } = require('agora-access-token');

const role = RtcRole.PUBLISHER;

const expirationTimeInSeconds = 3600

const currentTimestamp = Math.floor(Date.now() / 1000)

const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds

const generateAuthTokenToInititateCall = async (channel, cb) => {

const token = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channel, 0, role, privilegeExpiredTs);

cb({ "token": token, "channel": channel })

}

this is the node js code snippet

Is anyone able to resolve this? This is occurring despite setting the expiration to 3600 seconds (1 hour from current time).

let me make this token generation for you very simple and also the later process.

*firstly how to generate token?

you need a backend server which provides you with token when you provide the server a channel name. no where you will be told that this backend server is not necessary. rather you can copy - paste the token generation code directly into the app in a form of directory.

*where is this token generation code?

https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/java/src this code is available for flutter also research a little bit.

*how to generate token using it?

once you have the all java files in your project you can use them to generate the token. here you can see a variable expirationTimeInSeconds, that will be the total time you want token to be active. rest all work leave it to the code it will do it for you.

package io.agora.sample;

import io.agora.media.RtcTokenBuilder;
import io.agora.media.RtcTokenBuilder.Role;

public class RtcTokenBuilderSample {
    static String appId = "970CA35de60c44645bbae8a215061b33";
    static String appCertificate = "5CFd2fd1755d40ecb72977518be15d3b";
    static String channelName = "7d72365eb983485397e3e3f9d460bdda";
    static String userAccount = "2082341273";
    static int uid = 2082341273;
    static int expirationTimeInSeconds = 3600; 

    public static void main(String[] args) throws Exception {
        RtcTokenBuilder token = new RtcTokenBuilder();
        int timestamp = (int)(System.currentTimeMillis() / 1000 + expirationTimeInSeconds);
        String result = token.buildTokenWithUserAccount(appId, appCertificate,  
                 channelName, userAccount, Role.Role_Publisher, timestamp);
        System.out.println(result);
        
        result = token.buildTokenWithUid(appId, appCertificate,  
             channelName, uid, Role.Role_Publisher, timestamp);
        System.out.println(result);
    }
}

result here is the generated token which is valid for 3600 seconds, that is 1hour.

Related