0
votes

I am trying to create a LINE login authentication function on my web. The problem I am encountering is that I kept receiving error 400, a bad request which may have something to do with the parameter I've put in.

Here is my code,

    fetch('https://api.line.me/v2/oauth/accessToken', {
        method: 'POST',
        mode: 'no-cors',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: JSON.stringify({
            grant_type: 'authorization_code',
          client_id: 'my_id',
          client_secret: 'my_client_secret',
          code: code,
          redirect_uri: 'the link direct to'
        })
    }).then(response => {
      console.log(response);
    }).catch(function(err) {
      console.log(err);
    });

I followed the reference from LINE, https://developers.line.me/web-api/managing-access-tokens and put in the parameter it asked for, but I kept having the same error.

Tried with postman and got the same error

I am not sure which part I did wrong. Would someone help me with this issue?

2
Did you meant that postman worked but not the code? - Samuel Toh
Yes. Postman did give me the result. When I use the code above, I get 400 (bad request) - Hsin Hwang
Care to share with us the inputs for your postman query? E.g The Header and body. When you get http 400, is there other error messages in the response that can possibly be helpful? e.g. JSON.stringify(response) it - Samuel Toh
POST api.line.me/v2/oauth/accessToken 400 (Bad Request). - Hsin Hwang
This is the only error message shows up. Also, I take it back. I actually tried postman again and it's giving me the same error. I guess I was trying with the api.line.me/v1/oauth/accessToken link which gives me the output, but v1 is deprecated according to the document. - Hsin Hwang

2 Answers

0
votes

I've got the same error 400 problem. In my case, my redirect_uri contains parameter e.g. mysite.com?action=abc which not work. It accept something like mysite.com/action/abc.

0
votes

It seems no problem with your access token request.

Can you recheck the redirect_uri used by making an authorization request is same to the callback URL registered in the LINE console?

As described in the Line Login documents:

redirect_uri : Callback URL. URL that users are redirected to after authentication and authorization. Must match one of the the callback URLs registered for your channel in the console.