LINE Messaging APIを使って、LINEからSpotifyにログインしたいです(Eclipse + Node.js + herokuを利用しています)
自分で書いたindex.js内のエラーは一つずつ潰してきたのですが、今回インストールしたパッケージしかコンソールに表示されず困っています。
どなたか直すべきところや疑わしいところをご指摘いただけますと大変嬉しです。
よろしくお願いします。
<index.js>
'use strict';
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var request = require('request');
var async = require('async');
var crypto = require('crypto');
var https = require('https');
var qs = require('qs');
const line = require('@line/bot-sdk');
const client = new line.Client({
channelAccessToken: '---my Channel Access Token---'
});
app.use(express.static('public'));
app.set('port', (process.env.PORT || 8000));
app.use(bodyParser.urlencoded({extended: true})); // JSONの送信を許可
app.use(bodyParser.json()); // JSONのパースを楽に(受信時)
app.post('/callback', function(req, res) {
async.waterfall([
function(callback) {
console.log('req.headers is: ' + req.headers['x-line-signature']);
console.log('req.body is: ' + req.body);
console.log('validating result: ' + validate_signature(req.headers['x-line-signature'], req.body));
// 捕捉されない例外のスタックトレースを表示
process.on('unhandledRejection', console.dir);
// リクエストがLINE Platformから送られてきたか確認する
if (!validate_signature(req.headers['x-line-signature'], req.body)) {
return;
}
// テキストが送られてきた場合のみ返事をする
if ((req.body['events'][0]['type'] != 'message') || (req.body['events'][0]['message']['type'] != 'text')) {
return;
}
//署名検証
function validate_signature(signature, body) {
// return signature == crypto.createHmac('sha256', process.env.LINE_CHANNEL_SECRET).update(Buffer.from(JSON.stringify(body), 'utf8')).digest('base64');
return signature == crypto.createHmac('sha256', '3126eead2c2301a08ff7113b4a4c1347').update(Buffer.from(JSON.stringify(body), 'utf8')).digest('base64');
}
const client = new line.Client({
channelAccessToken: '---my Channel Access Token---'
});
// 送信データ作成
// テンプレートの内容
let pushSendMessageObject = [{
'replyToken': req.body['events'][0]['replyToken'],
"type": "template",
"altText": "this is a buttons template",
"template": {
"type": "buttons",
"title": "Spotifyにログインをお願いします。",
"text": "login",
"actions": [
{
"type": "uri",
"label": "はーい",
"uri": "https://accounts.spotify.com/authorize"
},
{
"type": "postback",
"label": "やめとく",
"data": "action=cancel&selectId=2"
},
]
}
}];
console.log('2 done');
callback(null, req, pushSendMessageObject);
},
function (req, pushSendMessageObject, callback){
client.replyMessage(req.body['events'][0]['replyToken'], pushSendMessageObject);
console.log('1 done');
setTimeout(function(){
callback(null);
}, 50);
}
],function(err){
if (err){
throw err;
console.log('This is an error message on the line 160');
}
}
);
});
app.listen(app.get('port'), function() {
console.log('Node app is running');
});
エラー内容は以下です。
[$ heroku logs
2018-03-19T11:40:48.090391+00:00 app[web.1]: headers: [Object],
2018-03-19T11:40:48.090392+00:00 app[web.1]: config: [Object],
2018-03-19T11:40:48.090394+00:00 app[web.1]: request: [Object],
2018-03-19T11:40:48.090396+00:00 app[web.1]: data: [Object] } } }
2018-03-19T11:41:17.678669+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/callback" host=ciecho.herokuapp.com request_id=4ff26185-f921-4af8-928c-53a9c05a1142 fwd="203.104.146.153" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2018-03-19T11:42:22.000000+00:00 app[api]: Build started by user [email protected]
2018-03-19T11:42:48.333058+00:00 app[api]: Deploy 096014ce by user [email protected]
2018-03-19T11:42:48.333058+00:00 app[api]: Release v152 created by user [email protected]
2018-03-19T11:42:22.000000+00:00 app[api]: Build succeeded
2018-03-19T11:42:49.235277+00:00 heroku[web.1]: Restarting
2018-03-19T11:42:49.236384+00:00 heroku[web.1]: State changed from up to starting
2018-03-19T11:42:50.364974+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-03-19T11:42:50.435324+00:00 heroku[web.1]: Process exited with status 143
2018-03-19T11:42:54.908997+00:00 heroku[web.1]: Starting process with command `node index.js`
2018-03-19T11:42:57.963816+00:00 app[web.1]: Node app is running
2018-03-19T11:42:58.711373+00:00 heroku[web.1]: State changed from starting to up
2018-03-19T11:43:15.632079+00:00 app[web.1]: req.headers is: SB9MLEAATN0YtWS/Q0tVTWb1WagzlQcqKWVwXGzxgKQ=
2018-03-19T11:43:15.633614+00:00 app[web.1]: 2 done
2018-03-19T11:43:15.635680+00:00 app[web.1]: 1 done
2018-03-19T11:43:15.633226+00:00 app[web.1]: validating result: true
2018-03-19T11:43:15.632340+00:00 app[web.1]: req.body is: [object Object]
2018-03-19T11:43:16.227644+00:00 app[web.1]: { Error: Request failed with status code 403
2018-03-19T11:43:16.227656+00:00 app[web.1]: at wrapError (/app/node_modules/@line/bot-sdk/dist/http.js:10:15)
2018-03-19T11:43:16.227659+00:00 app[web.1]: at <anonymous>
2018-03-19T11:43:16.227660+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:188:7)
2018-03-19T11:43:16.227662+00:00 app[web.1]: statusCode: 403,
2018-03-19T11:43:16.227664+00:00 app[web.1]: statusMessage: 'Forbidden',
2018-03-19T11:43:16.227665+00:00 app[web.1]: originalError:
2018-03-19T11:43:16.227667+00:00 app[web.1]: { Error: Request failed with status code 403
2018-03-19T11:43:16.227668+00:00 app[web.1]: at createError (/app/node_modules/axios/lib/core/createError.js:16:15)
2018-03-19T11:43:16.227670+00:00 app[web.1]: at settle (/app/node_modules/axios/lib/core/settle.js:18:12)
2018-03-19T11:43:16.227690+00:00 app[web.1]: at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:191:11)
2018-03-19T11:43:16.227692+00:00 app[web.1]: at emitNone (events.js:111:20)
2018-03-19T11:43:16.227694+00:00 app[web.1]: at IncomingMessage.emit (events.js:208:7)
2018-03-19T11:43:16.227698+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:138:11)
2018-03-19T11:43:16.227696+00:00 app[web.1]: at endReadableNT (_stream_readable.js:1056:12)
2018-03-19T11:43:16.227700+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:180:9)
2018-03-19T11:43:16.227703+00:00 app[web.1]: config:
2018-03-19T11:43:16.227704+00:00 app[web.1]: { adapter: [Function: httpAdapter],
2018-03-19T11:43:16.227706+00:00 app[web.1]: transformRequest: [Object],
2018-03-19T11:43:16.227708+00:00 app[web.1]: transformResponse: [Object],
2018-03-19T11:43:16.227709+00:00 app[web.1]: timeout: 0,
2018-03-19T11:43:16.227711+00:00 app[web.1]: xsrfCookieName: 'XSRF-TOKEN',
2018-03-19T11:43:16.227712+00:00 app[web.1]: xsrfHeaderName: 'X-XSRF-TOKEN',
2018-03-19T11:43:16.227714+00:00 app[web.1]: maxContentLength: -1,
2018-03-19T11:43:16.227715+00:00 app[web.1]: validateStatus: [Function: validateStatus],
2018-03-19T11:43:16.227717+00:00 app[web.1]: headers: [Object],
2018-03-19T11:43:16.227719+00:00 app[web.1]: method: 'post',
2018-03-19T11:43:16.227720+00:00 app[web.1]: url: 'https://api.line.me/v2/bot/message/reply',
2018-03-19T11:43:16.227729+00:00 app[web.1]: data: '{"messages":[{"replyToken":"f0e97d20499e4520be90046fb6541d8c","type":"template","altText":"this is a buttons template","template":{"type":"buttons","title":"Spotifyにログインをお願いします。","text":"login","actions":[{"type":"uri","label":"はーい","uri":"https://accounts.spotify.com/authorize"},{"type":"postback","label":"やめとく","data":"action=cancel&selectId=2"}]}}],"replyToken":"f0e97d20499e4520be90046fb6541d8c"}' },
2018-03-19T11:43:16.227731+00:00 app[web.1]: request:
2018-03-19T11:43:16.227733+00:00 app[web.1]: ClientRequest {
2018-03-19T11:43:16.227734+00:00 app[web.1]: domain: null,
2018-03-19T11:43:16.227736+00:00 app[web.1]: _events: [Object],
2018-03-19T11:43:16.227738+00:00 app[web.1]: _eventsCount: 6,
2018-03-19T11:43:16.227740+00:00 app[web.1]: _maxListeners: undefined,
2018-03-19T11:43:16.227741+00:00 app[web.1]: output: [],
2018-03-19T11:43:16.227743+00:00 app[web.1]: outputEncodings: [],
2018-03-19T11:43:16.227744+00:00 app[web.1]: outputCallbacks: [],
2018-03-19T11:43:16.227746+00:00 app[web.1]: outputSize: 0,
2018-03-19T11:43:16.227748+00:00 app[web.1]: writable: true,
2018-03-19T11:43:16.227749+00:00 app[web.1]: _last: true,
2018-03-19T11:43:16.227751+00:00 app[web.1]: upgrading: false,
2018-03-19T11:43:16.227752+00:00 app[web.1]: chunkedEncoding: false,
2018-03-19T11:43:16.227754+00:00 app[web.1]: shouldKeepAlive: false,
2018-03-19T11:43:16.227755+00:00 app[web.1]: useChunkedEncodingByDefault: true,
2018-03-19T11:43:16.227757+00:00 app[web.1]: sendDate: false,
2018-03-19T11:43:16.227759+00:00 app[web.1]: _removedConnection: false,
2018-03-19T11:43:16.227760+00:00 app[web.1]: _removedContLen: false,
2018-03-19T11:43:16.227762+00:00 app[web.1]: _removedTE: false,
2018-03-19T11:43:16.227764+00:00 app[web.1]: _contentLength: null,
2018-03-19T11:43:16.227765+00:00 app[web.1]: _hasBody: true,
2018-03-19T11:43:16.227767+00:00 app[web.1]: _trailer: '',
2018-03-19T11:43:16.227768+00:00 app[web.1]: finished: true,
2018-03-19T11:43:16.227770+00:00 app[web.1]: _headerSent: true,
2018-03-19T11:43:16.227771+00:00 app[web.1]: socket: [Object],
2018-03-19T11:43:16.227773+00:00 app[web.1]: connection: [Object],
2018-03-19T11:43:16.227776+00:00 app[web.1]: _header: 'POST /v2/bot/message/reply HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/json\r\nAuthorization: Bearer mGKjMIpknOpyCQ7VdpNWjOw1jjwCJJxM0qRuojibKdChbfusZlUl/2DcCbS3A6cX4QWQ58yGZrKcH8pxXjmPwHMTKavxKhXGjIT3vFh5Z1NL8kUGnznrEM7QPCSQrPq+17OQgzIDWnUW/mP5abzpSgdB04t89/1O/w1cDnyilFU=\r\nUser-Agent: @line/bot-sdk/5.2.0\r\nContent-Length: 442\r\nHost: api.line.me\r\nConnection: close\r\n\r\n',
2018-03-19T11:43:16.227778+00:00 app[web.1]: _onPendingData: [Function: noopPendingOutput],
2018-03-19T11:43:16.227779+00:00 app[web.1]: agent: [Object],
2018-03-19T11:43:16.227781+00:00 app[web.1]: socketPath: undefined,
2018-03-19T11:43:16.227782+00:00 app[web.1]: timeout: undefined,
2018-03-19T11:43:16.227784+00:00 app[web.1]: method: 'POST',
2018-03-19T11:43:16.227786+00:00 app[web.1]: path: '/v2/bot/message/reply',
2018-03-19T11:43:16.227787+00:00 app[web.1]: _ended: true,
2018-03-19T11:43:16.227789+00:00 app[web.1]: res: [Object],
2018-03-19T11:43:16.227790+00:00 app[web.1]: aborted: undefined,
2018-03-19T11:43:16.227792+00:00 app[web.1]: timeoutCb: null,
2018-03-19T11:43:16.227794+00:00 app[web.1]: upgradeOrConnect: false,
2018-03-19T11:43:16.227795+00:00 app[web.1]: parser: null,
2018-03-19T11:43:16.227798+00:00 app[web.1]: _redirectable: [Object],
2018-03-19T11:43:16.227797+00:00 app[web.1]: maxHeadersCount: null,
2018-03-19T11:43:16.227800+00:00 app[web.1]: [Symbol(outHeadersKey)]: [Object] },
2018-03-19T11:43:16.227802+00:00 app[web.1]: response:
2018-03-19T11:43:16.227803+00:00 app[web.1]: { status: 403,
2018-03-19T11:43:16.227805+00:00 app[web.1]: statusText: 'Forbidden',
2018-03-19T11:43:16.227806+00:00 app[web.1]: headers: [Object],
2018-03-19T11:43:16.227808+00:00 app[web.1]: config: [Object],
2018-03-19T11:43:16.227810+00:00 app[web.1]: request: [Object],
2018-03-19T11:43:16.227811+00:00 app[web.1]: data: [Object] } } }