Node.js错误:Route.post()需要回调函数,但得到了[object Object]

时间:2018-07-08 09:42:58

标签: node.js stripe-connect

我正在运行Node.js脚本,使用这些说明https://stripe.com/docs/connect/standard-accounts#token-request

从Stripe获取JSON响应。

但是,我在以下代码中遇到以下错误:

  

错误:Route.post()需要回调函数,但是得到了[object Object]

代码

var app = express();
var stripe = require('stripe')('sk_test_XXXXXXXXXXXXXXXX')
var bodyParser = require('body-parser')
var request = require('request')

app.post('/ptaccountid',(req,res) => {

  var authCode = req.body.code;

  app.post('https://connect.stripe.com/oauth/token', {
    form: {
     client_secret: "sk_test_XXXXXXXXXXXXXXXX",
     code: authCode,
     grant_type: "authorization_code",
    }
 }, function(err, response, body) {
    if (!err && response.statusCode == 200) {
      console.log(body)
  }
});
}); 

1 个答案:

答案 0 :(得分:0)

您应该使用request.post而不是app.post

检查以下代码,

app.post('/ptaccountid',(req,res) => {
    var authCode = req.body.code;

    request.post('https://connect.stript.com/oauth/token', {
          form: {
           client_secret: "sk_test_XXXXXXXXXXXXXXXX",
           code: authCode,
           grant_type: "authorization_code",
          }
        }, function(err, response, body) {
          if (!err && response.statusCode == 200) {
            console.log(body)
        }
    });
}); 

希望这会有所帮助!