Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

How to deal with token-related error codes?

When a primary/secondary certificate is enabled for your project, you use dynamic tokens to authenticate users. This page lists token-related error codes and event callbacks you may receive, provides triggering causes and solutions, and helps you troubleshoot.

101: App Id invalid

Problem

The SDK for native platforms returns the ERR_INVALID_APP_ID (101) error code when initializing the Agora service. Alternatively, the SDK calls back the onError event and returns the ERR_INVALID_APP_ID (101) error code when calling joinChannel.

Cause

An invalid App Id usually caused by the incorrect data type.

Solution

Check that the App Id data type is string and reinitialize the service.

109: Token expired

Problem

The SDK for native platforms triggers the onError event and returns the ERR_TOKEN_EXPIRED (109) error code when calling joinChannel.

Cause

The token has expired.

Solution

If the token has expired, generate a new token on the server and call renewToken to rejoin the channel.

110: Token invalid

Problem

The SDK for native platforms triggers the onError event and returns the ERR_INVALID_TOKEN (110) error code when calling joinChannel.

Cause

The generated token is invalid. This may happen for one of the following reasons:

  • Primary/secondary certificate is enabled in your project, but the token is not passed when joining the channel. Alternatively, primary/secondary certificate is not enabled, but the token is passed to join the channel.

  • The App Id, user ID, and channel name you used when generating the token on the server do not match the values you filled in when initializing and joining the channel.

Solution

Before joining the channel, check whether the project corresponding to the App Id you filled in during initialization has a primary/secondary certificate enabled.

  • If primary/secondary certificate is not enabled, you cannot use a token to join the channel.
  • If primary/secondary certificate is enabled in the project and App Id-only joining is allowed, you can join the channel using only the App Id or using the token generated by the primary/secondary certificate to join the channel.
  • If primary/secondary certificate is enabled in your project and App Id-only joining is not allowed, you must use a token to join the channel.

When confirming the use of a token to join the channel, also confirm the following:

  • The App Id used to generate the token is consistent with the App Id filled in when initializing the token server.
  • The user ID used to generate the token is consistent with the user ID filled in when joining the channel, and the data type is also consistent.
  • The channel name used to generate the token is consistent with the channel name filled in when joining the channel.

Token expiration event callback

To improve the communication experience, Agora provides the following two callbacks to inform the client that their token is about to expire or has expired:

  • onTokenPrivilegeWillExpire: This callback indicates that the token will expire within 30 seconds. When you receive this callback, generate a new token on the server side and call renewToken to pass the newly generated token to the SDK.
  • onRequestToken: This callback indicates that the token has expired. When you receive this callback, generate a new token on the server side and call joinChannel to rejoin the channel.

Error code comparison

The table below provides the error code equivalents for different languages.

Error codeJava/C++/C#Objective-C
101ERR_INVALID_APP_IDAgoraErrorCodeInvalidAppId
109ERR_TOKEN_EXPIREDAgoraErrorCodeTokenExpired
110ERR_INVALID_TOKENAgoraErrorCodeInvalidToken
vundefined