LoginSignup
1
1

More than 3 years have passed since last update.

COTOHA アクセストークンの取得 (Node.js)

Last updated at Posted at 2020-02-22

COTOHA API Portal の使用例です。

次と同じことを Node.js で行いました。

COTOHA アクセストークンの取得

access_token.js
#! /usr/bin/node
// ---------------------------------------------------------------
//
//  access_token.js
//
//                  Feb/22/2020
//
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
const dotenv = require('dotenv')
var Client = require('node-rest-client').Client

dotenv.config()

var config = {
    client_id: `${process.env.CLIENT_ID}`,
    client_secret: `${process.env.CLIENT_SECRET}`,
    developer_api_base: `${process.env.DEVELOPER_API_BASE_URL}`,
    access_token_publish_url: `${process.env.ACCESS_TOKEN_PUBLISH_URL}`,
}

const data = {
    "grantType": "client_credentials",
    "clientId": config.client_id,
    "clientSecret": config.client_secret
    }

const url = config.access_token_publish_url

const headers={
    "Content-Type": "application/json"
    }

const args = {
    data: data,
    headers: headers
}

var client = new Client()

client.post(url, args, function (data, response) {
    console.log(data)
    console.error ("*** 終了 ***")
})

// ---------------------------------------------------------------

実行コマンド

export NODE_PATH=/usr/lib/node_modules
./access_token.js

使ったバージョン

$ node --version
v13.9.0
1
1
0

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
1
1