Select to view content in your preferred language

World Traffic Service failed to render due to Authentication issue.

649
6
Jump to solution
01-19-2026 05:06 AM
PrashantGaykar
Occasional Contributor

Hi There,

We are using Kotlin Maps SDK (version : 200.8.0) in our Android App to display maps.

Our QA backend release new URL to display traffic heat layer.
URL : https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer

Whenever app tries to load traffic layer using this url the SDK throws following error.
An ArcGIS authentication error occurred when accessing https://www.arcgis.com. An API key or credential may be required. For more information see https://developers.arcgis.com/kotlin/security-and-authentication/.

Following is my code to render traffic layer in Kotlin.

fun getTrafficLayer(accessToken: String): BasemapResult.AsLayer {
ArcGISEnvironment.apiKey = ApiKey.create(accessToken)
val newLayer = ArcGISMapImageLayer("https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer/")
newLayer.name = "Traffic Layer"
return BasemapResult.AsLayer(newLayer)
}


I am getting accessToken from backend.

although other layers (vector,satellite) able to load successfully with same API Key.

I tried to load this traffic URL on web with access token and few other parameter and worked successfully.
e.g. : https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer/export?bbox=2969828.76837809...

It means there is no issue with access token.
I dont know why it is failing to authenticate on Mobile only. 

Is this an API Key issue ? Does traffic service needs to be enabled for this particular API Key / Account ?

Please help me resolved this issue.

Regards,
Prashant

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
MikeWilburn
Esri Contributor

It turns out this is a known limitation where API keys cannot be used to access ArcGIS map image layers directly. However, we can still get this to work by creating a PregeneratedTokenCredential with your API key and adding this to the ArcGIS credential store.

Here's how that would look:

val trafficLayer = "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer/"

val tokenInfo = TokenInfo(
    accessToken = apiKey.toString(),
    expirationDate = Instant.now().plus(Duration.ofHours(2)), //an expiration equal to or less than your API key expiration
    isSslRequired = true
)
val trafficCredential = PregeneratedTokenCredential(
    url = trafficLayer,
    tokenInfo = tokenInfo
)

// Ensure that you add the credential to the store prior to loading the layer
ArcGISEnvironment.authenticationManager.ArcGISCredentialStore.add(trafficCredential)

// Continue with loading the traffic layer

View solution in original post

0 Kudos
6 Replies
MikeWilburn
Esri Contributor

Hi Prashant, sorry about the delay in responding here. Can you please confirm a couple of details to help us with our investigation?

  1. For the API key access token you are creating, is this through an ArcGIS Location Platform account, or an ArcGIS Online account?
  2. In your two efforts to gain access to the traffic servicefirst via your Kotlin app, and second via URL (presumably browser)is the access token you're supplying the same one? Or are you creating these separately?
0 Kudos
PrashantGaykar
Occasional Contributor

Hi @MikeWilburn , thank you for replying.
following are the answer's to your questions respectively.

1. We are using ArcGIS Online account to create access token.
2. For both platforms (App and Web) we are using different access token. We also tried using Web access token in app but faced same error.

0 Kudos
MikeWilburn
Esri Contributor

It turns out this is a known limitation where API keys cannot be used to access ArcGIS map image layers directly. However, we can still get this to work by creating a PregeneratedTokenCredential with your API key and adding this to the ArcGIS credential store.

Here's how that would look:

val trafficLayer = "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer/"

val tokenInfo = TokenInfo(
    accessToken = apiKey.toString(),
    expirationDate = Instant.now().plus(Duration.ofHours(2)), //an expiration equal to or less than your API key expiration
    isSslRequired = true
)
val trafficCredential = PregeneratedTokenCredential(
    url = trafficLayer,
    tokenInfo = tokenInfo
)

// Ensure that you add the credential to the store prior to loading the layer
ArcGISEnvironment.authenticationManager.ArcGISCredentialStore.add(trafficCredential)

// Continue with loading the traffic layer
0 Kudos
PrashantGaykar
Occasional Contributor

Hi @MikeWilburn , Thank you for the code. 

I will try this and let you know if this works.

0 Kudos
PrashantGaykar
Occasional Contributor

Hi @MikeWilburn , your solution worked. Thank you very much !

0 Kudos
MikeWilburn
Esri Contributor

Fantastic - glad to hear it!

0 Kudos