14
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NodejsでQiita APIに接続できない

Last updated at Posted at 2014-03-10

Node.jsでQiita APIに接続したいと思い、こんなjsを書いてみました。

auth.js
var request = require("request");

var options = {
  form: { url_name: 'xxxxx', password: 'xxxxxxxxxxx' },
  json: true
};

request.post('https://qiita.com/api/v1/auth/', options, function(error, response, body){
  if (!error && response.statusCode == 200) {
    console.log(body);
  } else {
    console.log(error);
  }
});

すると、こんなエラーが…

$ node auth.js
[Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE]

どうやらパラメータにrejectUnauthorized: falseを加えるとうまく動くようです。

var options = {
  rejectUnauthorized: false,  // これを追加する
  form: { url_name: 'xxxxx', password: 'xxxxxxxxxxx' },
  json: true
};

SSLのサーバー証明書が不正なのかなー。

---- 追記 3/11 12:20 ----
どうやら直ったみたいで、tokenがちゃんと返ってくるようになりました。
kimama1997さん、Qiitaの中の方ありがとうございました。

14
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?