0

I have integrated Agora video calling libs in the android project. When I use temp token then video calling working perfectly but if I create a dynamic token then I get the error code 101. I have created a dynamic token in RtcTokenBuilder Method.

implementation 'io.agora.rtc:full-sdk:3.0.0'

RtcTokenBuilder Class Link : https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/java/src/main/java/io/agora/media/RtcTokenBuilder.java

RtcTokenBuilderSample Link : https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/java/src/main/java/io/agora/sample/RtcTokenBuilderSample.java

    RtcTokenBuilder token = new RtcTokenBuilder();
    int timestamp = (int) (System.currentTimeMillis() / 1000 + expirationTimeInSeconds);
    String result = token.buildTokenWithUserAccount(appId, appCertificate, chenal, "0", RtcTokenBuilder.Role.Role_Publisher, timestamp);
    Log.e("live Token", "***************Token: tkn == " + result);
Pravin Suthar
  • 1,403
  • 1
  • 14
  • 25

1 Answers1

0

Error code says that the appId which was used to generate the token doesn't match the one which is getting verified when you are doing a joinChannel call. Ensure that you have the appId and appCertificate right (which are found in https://console.agora.io/ inside the project you might have already created.)


public String getRtcToken(String channelName,  int roleValue, Long expiryDurationInSecs) {
    Long expiryTimestamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + expiryDurationInSecs;
    RtcTokenBuilder builder = new RtcTokenBuilder();
    io.agora.media.RtcTokenBuilder.Role role = io.agora.media.RtcTokenBuilder.Role.Role_Subscriber;
    if (io.agora.media.RtcTokenBuilder.Role.Role_Publisher.initValue == roleValue) {
        role = io.agora.media.RtcTokenBuilder.Role.Role_Publisher;
    }

    return builder.buildTokenWithUid(this.appId, this.appCertificate, channelName, 0, role, expiryTimestamp.intValue());
}
viv3k
  • 621
  • 4
  • 10
  • When I created a temp token from the console, it is working but when I try with the dynamic token (i have mentioned in the question how I create dynamic token) it is not working. – Pravin Suthar Nov 02 '21 at 05:36
  • Did you replace the appId and appCertificate strings in your code? – viv3k Nov 02 '21 at 10:49
  • Yes, I have already replaced the appId and appCertificate in the string. – Pravin Suthar Nov 02 '21 at 10:51
  • Use `token.buildTokenWithUid` instead of `token.buildTokenWithUserAccount`. Refer the code in the updated answer. – viv3k Nov 02 '21 at 14:12