更新时间:2022-11-24 17:55:25
这个答案怎么样?请认为这只是几个答案之一.
How about this answer? Please think of this as just one of several answers.
不幸的是,Node.js的模块不能直接用于Google Apps脚本.因此,需要为Google Apps脚本准备脚本.幸运的是,在您提出的问题的链接的官方文档中,有几个示例.使用此方法,如何转换为Google Apps脚本的脚本?
Unfortunately, the module of Node.js cannot be directly used for Google Apps Script. So it is required to prepare the script for Google Apps Script. Fortunately, at the official document of the link in your question, there are several samples. Using this, how about converting to the script of Google Apps Script?
将您问题中的脚本转换为Google Apps脚本后,它就会如下所示.
When your script in your question is converted to Google Apps Script, it becomes as follows.
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
(async () => {
const product = await stripe.products.create({
name: 'My SaaS Platform',
type: 'service',
});
})();
function myFunction() {
var url = "https://api.stripe.com/v1/products";
var params = {
method: "post",
headers: {Authorization: "Basic " + Utilities.base64Encode("sk_test_4eC39HqLyjWDarjtT1zdp7dc:")},
payload: {name: "My SaaS Platform", type: "service"}
};
var res = UrlFetchApp.fetch(url, params);
Logger.log(res.getContentText())
}
sk_test_4eC39HqLyjWDarjtT1zdp7dc
被用作密钥.但是在这种情况下,由于使用了基本授权,因此请添加:
来使用sk_test_4eC39HqLyjWDarjtT1zdp7dc:
.sk_test_4eC39HqLyjWDarjtT1zdp7dc
is used for the key. But in this case, because the basic authorization is used, please use sk_test_4eC39HqLyjWDarjtT1zdp7dc:
by adding :
.如果我误解了你的问题,而这不是你想要的方向,我深表歉意.
If I misunderstood your question and this was not the direction you want, I apologize.