0
  'use strict'
    var express = require('express');
    var bodyParser = require('body-parser');
    var request = require('request');
    var awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');
    var app = express();
    var port = process.env.PORT || 5000;
    var VALIDATION_TOKEN = 'Serverless_My_Token';
    app.set('port', (port));
// Process application/x-www-form-urlencoded
    app.use(bodyParser.urlencoded({extended: true}));
app.use(awsServerlessExpressMiddleware.eventContext());
    // Process application/json
    app.use(bodyParser.json());
// for Facebook verification
        app.get('/webhook/', function (req, res) {
            var jsonObject = JSON.parse(req.rawHeaders[1]);
            if (jsonObject.params.querystring['hub.verify_token'] === 'serverless_my_token') {
         var hubChallenge = jsonObject.params.querystring['hub.challenge'];

         return res.send(hubChallenge);
    }
    res.send('Error, wrong token')
        });

当调用 get API res.send 发送整个响应对象时,

{
  "statusCode": 200,
  "body": "",
  "headers": {
  },
  "isBase64Encoded": false
}

我只需要发送 hubChallenge 变量作为响应:

hub.challenge number:示例:245421998 作为响应。

如何仅将 hubchallenge 变量作为响应而不是包含状态的整个对象返回。ETC..

错误:

The URL couldn't be validated. Response does not match challenge, expected value="245421998", received="{\"statusCode\":200,..."
4

1 回答 1

0

你不应该在app = express();你的代码之后的某个地方添加这个:

app.use(awsServerlessExpressMiddleware.eventContext());

现在它接缝你导入awsServerlessExpressMiddleware但你没有在你的应用程序的任何地方使用它。

于 2017-02-03T10:45:24.653 回答