Managing access tokens

The LINE SDK for Android contains methods to get the current access token, verify that the token is valid, and refresh the token. The SDK automatically refreshes access tokens that are expired whenever an API call is made through the LineApiClient interface.

Before you begin

Make sure you have completed the following:

About access tokens

Access tokens are valid for 30 days after being issued. When an access token expires, API calls fail and a corresponding error is returned. Whenever you call a method on LineApiClient, the SDK automatically verifies the validity of the access token and refreshes the token if it has expired. If the token cannot be refreshed, you must prompt the user to log in again to get a new access token.

The access token is deleted when the user deletes your app. If the user reinstalls your app, you must prompt the user to log in again to get a new access token.

Getting the current access token

If you have a client-server application, you can get the current access token to make API calls from your server. Once you get the access token, you can call the Social API. For more information, see the API reference.

To get the current access token, call the getCurrentAccessToken() method.

String accessToken = lineApiClient.getCurrentAccessToken().getResponseData().getAccessToken();

Note: When sending access tokens to your server, we recommend encrypting the token and using SSL to send the encrypted data. You should also verify that the access token received by your server matches the access token used to call the Social API and that the channel ID matches the one for your channel.

Verifying access tokens

To verify the validity of the current access token, use the verifyToken() method. This method returns a LineApiResponse object that contains the result. You can then call the isSuccess() method to check if the token is valid. If isSuccess() is true, the token is valid. Otherwise the access token is invalid, expired, or the API call failed in some manner.

If isSuccess() is FALSE, use the LineApiResponse.getErrorData() method to get more information about why the verifyToken() method failed. getResponseData() returns NULL.

LineApiResponse verifyResponse = lineApiClient.verifyToken();

if (verifyResponse.isSuccess()) {

    Log.i(TAG, "getResponseData: " + verifyResponse.getResponseData().toString());
    Log.i(TAG, "getResponseCode: " + verifyResponse.getResponseCode().toString());

    return true;

} else {

    Log.i(TAG, "getResponseCode: " + verifyResponse.getResponseCode());
    Log.i(TAG, "getErrorData: " + verifyResponse.getErrorData());

    return false;


To get a list of permissions that are associated with the access token, call LineApiResponse.getPermission(). The following example demonstrates how to display a list of permissions in a toast.


protected void onPostExecute(LineApiResponse response){

    if (response.isSuccess()){
        StringBuilder toastStringBuilder = new StringBuilder("Access Token is VALID and contains the permissions: ");

        for (String temp : response.getResponseData().getPermission()) {
            toastStringBuilder.append(temp + ", ");
        Toast.makeText(getApplicationContext(), toastStringBuilder.toString(), Toast.LENGTH_SHORT).show();

Refreshing access tokens

To refresh the access token that is currently being used by the SDK, call the refreshAccessToken() method. You can call this method for up to 90 days after the access token has expired. If this call fails, then it means that the refresh token has expired and the user must log in again to get a new access token.


Handling errors

The following HTTP status codes are returned when an API is called.

Status code Description
200 OK Request successful
400 Bad Request Problem with the request. Check the request parameters and JSON format.
401 Unauthorized Check that the authorization header is correct.
403 Forbidden Not authorized to use the API. Confirm that your account or plan is authorized to use the API.
429 Too Many Requests Make sure that you are within the rate limits for requests.
500 Internal Server Error Temporary error on the API server.

{{ $t("form.question.helpful") }}

{{ $t("form.question.detail") }}

{{ $t("form.question.improve") }}

{{ $t("") }}{{ $t("") }}{{ $t("") }}

{{ $t("form.result.success") }}
{{ $t("form.result.error") }}
{{ $t("form.result.errorLink") }}