# User Access Token

The user access token allows you to interact with the Sentiance API directly from within your app.

## Get the User ID and Token

If a Sentiance user has been created, you can get the user ID and token as follows:

{% tabs %}
{% tab title="iOS" %}

```objectivec
 Sentiance.shared.requestUserAccessToken { result, error in
    if let result = result {
        print("Token: \(result.token)")
    }
}
```

{% endtab %}

{% tab title="Android" %}

```java
sentiance.requestUserAccessToken().addOnCompleteListener { operation ->
    if (operation.isSuccessful) {
        val token = operation.result
    } else {
        val error = operation.error
        Log.e(TAG, "Failed to get access token, reason ${error.reason.name}.")
    }
}
```

{% endtab %}
{% endtabs %}

## Failure

The token is normally valid for a limited time (several days). Generally, requesting a token from the SDK will complete instantly by returning a cached token. But if a new one has to be obtained from the Sentiance API, there is a possibility that it will fail (e.g. no network connection).

{% hint style="info" %}
Use `error.failureReason` to know the failure reason in case of failure.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sentiance.com/important-topics/sdk/appendix/user-access-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
