L
L
lex2016-10-12 01:58:37
JavaScript
lex, 2016-10-12 01:58:37

How to fix nodejs request error?

Greetings, tell me why it doesn’t work, I don’t understand, it says
{"error_description": "grant_type not in POST", "error": "invalid_request"}
what is wrong?)

var options = {
        "grant_type": "authorization_code",
        "code": code,
        "client_id": ci,
        "client_secret": cs
      };
      var opt = {
        "url": "https://oauth.yandex.ru/token",
        "method": "POST",
        "headers": {
            'Content-type': 'application/x-www-form-urlencoded'
        },
        "grant_type": "authorization_code",
        "code": code,
        "client_id": ci,
        "client_secret": cs
      };

      request.post(opt, (req, res) => {
        console.log(opt);
        var body = res.body;
        console.log(body);
      });

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Nemiro, 2016-11-10
@cimonlebedev

You have a colon where a semicolon should be:

case valMetr == 0:
  valMetr = 0: // <<===== ошибка, должна быть точка с запятой
  break;
case valMetr>1 && valMetr<=49:
  valMetr = 30: // <<===== ошибка, должна быть точка с запятой
  break;

Instead of such a switch construct, it is better to use if ... else .
It will work faster , at least :-)

G
GavriKos, 2016-11-10
@GavriKos

Because you're cooking it wrong. In switch you should have valMetr and in case you should have values. For intervals, switch-case is not very applicable.

D
Denis, 2016-11-10
@cjbars

something like this, but this is not the best use of switch

switch(valMetr){
        case 0:
        case 1:
        case 2:
// еще 47 строчек
        case 49:
          valMetr = 0:
          break;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question