Question Details

What is the proper way to make the API request to verify the access token?

I keep getting the "error_description": "The access token malformed". Not sure how to fix this. Any help would be much appreciated. Have tried the follwoing two methods to make the request:

Method 1:

<!-- Use the below function to create vrifyTokenOptions object -->

function generateLineApiRequest(apiEndpoint, lineAccessToken) { return { url: apiEndpoint, headers: { 'Authorization': Bearer ${lineAccessToken}, }, json: true, }; } // Send request to LINE server for access token verification const verifyTokenOptions = generateLineApiRequest('', lineAccessToken); return request(verifyTokenOptions) .then(response => {...

Method 2

<!-- No need for headers -->

var apiEndpoint = '' + lineAccessToken; return request({ method: 'GET', uri: apiEndpoint, json: true }).then((response) => {...

Profile picture


Profile picture
Posted: 3 months ago

You cannot actually verify the access_token, you can only use it or generate a new one.

So, basically, you make your messaging_api calls like normal and if you get a 401 Unauthorized, you know you need to generate a new access_token.

Something like:

  response = await'', {
      grant_type:    'client_credentials',
      client_id:     channel_id,
      client_secret: channel_secret,
      content_type:  'form',
      authorization: 'oauth',
		// response = { "access_token": "XXXXXX", "expires_in": 2592000, "token_type": "Bearer" }
Are you sure? question.vm