你好我在文档的这一点上 https://stripe.com/docs/connect/standalone-accounts#token-request
所以我的问题是我不知道如何在节点中发布Post请求,
我已经尝试了很多例子但是无法得到它。有人可以指导我正确的方向,谢谢。修改
这是我尝试过的
var app = express();
var server = app.listen(process.env.PORT || 3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
request.post(
'https://connect.stript.com/oauth/token', {
form: {
client_secret: "sk_test_QWnyIomfd2glLk9whe6gOC4f",
code: "AUTHORIZATION_CODE",
grant_type: "authorization_code",
}
},
function (error, response, body) {
console.log(response)
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
这是我在跳过帐户表格时得到的内容
Cannot GET /?scope=read_write&code=ac_6B0uydoV7XrniZrssm3m2sivUx49cA8M
答案 0 :(得分:2)
您获得Cannot GET /?scope=read_write&code=ac_6B0uydoV7XrniZrssm3m2sivUx49cA8M
的原因是当条带尝试重定向到您在平台设置下设置的重定向URI时,您可能错过了设置重定向URI的过程,当条带将代码发送到您的url以下列方式
app.get('/redirecurlforstripe',function(req,res){
var params = req.body; // or req.params.query; see which one works for you
request.post(
'https://connect.stript.com/oauth/token', {
form: {
client_secret: "sk_test_QWnyIomfd2glLk9whe6gOC4f",
code: params.code, //this will be the authorization code coming from stripe
,
grant_type: "authorization_code",
}
},
function (error, response, body) {
console.log(response)
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
});
答案 1 :(得分:0)
我将条带上的redirectUrl设置为http://127.0.0.1:8081/authorize
以下是我在服务器端使用的代码:
var CLIENT_ID = 'Your client_id';
var API_KEY = 'Your API_KEY';
var TOKEN_URI = 'https://connect.stripe.com/oauth/token';
var AUTHORIZE_URI = 'https://connect.stripe.com/oauth/authorize';
var qs = require('querystring');
var request = require('request');
var express = require('express');
var app = express();
app.get('/authorize', function(req, res) {
var code = req.query.code;
// Make /oauth/token endpoint POST request
request.post({
url: TOKEN_URI,
form: {
grant_type: 'authorization_code',
client_id: CLIENT_ID,
code: code,
client_secret: API_KEY
}
}, function(err, r, body) {
var accessToken = JSON.parse(body).access_token;
// Do something with your accessToken
// For demo's sake, output in response:
res.send({ 'Your Token': accessToken });
console.log(body);
});
});
app.listen(8081);
答案 2 :(得分:0)
该错误来自条纹连接的错误URL。 'https://connect.stript.com/oauth/token'
您应该将其更改为 'https://connect.stripe.com/oauth/token'
在我这方面效果很好。