Q&A

Why can't I get an access token?

前提・実現したいこと

get access token

発生している問題・エラーメッセージ

503 (Service Unavailable)

該当のソースコード

const express = require("express"); const app = express(); const url = require("url"); const querystring = require("querystring"); const qs = require("qs"); const fetch = require('node-fetch')

app.use(express.static("public"));

// define the first route app.get("/auth", function (req, res) { let reqURL = req.url; let queryData = url.parse(reqURL, true).query;

fetch("https://api.line.me/oauth2/v2.1/token", { method: "POST", body: new URLSearchParams({ grant_type: "authorization_code", code: ${queryData.code}, client_id: "", client_secret: "", }), }).then(res=>res.json();) .then(data=>{ res.send("HI " + qs.stringify(data)); }) });

app.listen(process.env.PORT || 3000, () => console.log("Server is running..."));

試したこと

all i can do

補足情報(FW/ツールのバージョンなど)

Nodejs, heroku

  • 0
  • 2
  • 364
  • twitter facebook

I have solved this problem. There was a mistake in the syntax. Thanks for your interest in my problem.

  • 0

I think you need to add catch on your fetch call to get error message.

fetch("url", { param })
  .then(res => { your code })
	.then(data => { your code })
	.catch(err => console.error(err))
  • 2
本当によろしいですか? question.vm