I would like to know how to deal with 401 errors when using LINE Messaging API on GAS.

Asked 1 years ago, Updated 1 years ago, 122 views

When I run Webhook verification on LINE developers, the bot server returns a non-200 HTTP status code, which is troubling me with the error .
Does anyone know the cause or solution?

The results are as follows:

error

The bot server returned a non-200 HTTP status code

Image

Incidentally, the error status code was 401.

Image

I thought that the verification would go well.
This is because I followed the instructions in Google Apps Script and made LINE BOT work in 30 minutes.

To determine the cause, we tried the following steps.

(a) Review Messaging API Documentation

"No valid channel access token specified"

(b) Check the channel access token in LINE Devaloppers

Channel access token used to invoke the Messaging API.This channel access token does not expire.Click Publish to issue a new channel access token or replace an existing channel access token.

As mentioned above, I will reissue it and set up the webhook in GAS again,
Update → Paste the public URL to LINE Devaloppers

There was no change in the results.

Are there any other procedures for authentication on the LINE side?
https://developer.mozilla.org/

Another possible cause is

  • With LINE developers, you have not configured anything
  • There is a problem with the code in the GAS code

and so on, but I would like to know where the 401 error is.

(From the case where I made LINE BOT in Google Apps Script and it worked in 30 minutes)

// Access tokens listed in LINE developers message sending and receiving settings
varACCESS_TOKEN='----------------------------------------------------------------------------------------

function doPost(e){
  // Response Token Received by WebHook
  var replyToken=JSON.parse(e.postData.contents).events[0].replyToken;
  // Get user messages
  var userMessage=JSON.parse(e.postData.contents).events[0].message.text;
  // API URL for response messages
  varurl='https://api.line.me/v2/bot/message/reply';

  UrlFetchApp.fetch(url,{
    'headers': {
      'Content-Type': 'application/json; charset=UTF-8',
      'Authorization': 'Bearer' + ACCESS_TOKEN,
    },
    'method': 'post',
    'payload': JSON.stringify({
      'replyToken': replyToken,
      'messages': [{
        'type': 'text',
        'text': userMessage + 'ngo',
      }],
    }),
  });
  returnContentService.createTextOutput(JSON.stringify({'content':'postok'}))).setMimeType(ContentService.MimeType.JSON);
}

My environment is as follows.
macOS Mojave 10.14.5

api google-apps-script line

2022-09-30 21:44

1 Answers

You must enable public access in Google Apps Script side settings.

This solves the problem, but you will also receive messages from non-LINE, so you will need to determine if LINE sent them in the actual bot implementation.


2022-09-30 21:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.