【发布时间】:2019-04-12 20:28:25
【问题描述】:
我正在尝试通过 Stripe API 在 Google 表格中 retrieve an invoice,并且我正在使用 Google Apps 脚本来运行我的代码。这是我的代码:
function callNumbers()
{
var url = "https://api.stripe.com/v1/invoices/[unique_id]";
var apiKey = "[api-key]";
var response = UrlFetchApp.fetch(url, {"headers":{"[api-key]":apiKey}});
var content = response.getContentText();
Logger.log(response);
Logger.log(content);
}
Stripe 发票 URL 在上面的 /invoices/ 之后的 URL 中有一个唯一 ID,代表我要检索的特定测试发票。
我使用的是test Stripe API key,它在唯一的 API 密钥代码之前以此开头:sk_test_
Stripe 页面上的引用如下所示:
curl https://api.stripe.com/v1/invoices/[unique_id] \
-u sk_test_[api-key]:
我收到的错误信息如下所示:
Request failed for https://api.stripe.com/v1/invoices/[unique_id] returned code 401. Truncated server response: { "error": { "message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g... (use muteHttpExceptions option to examine full response) (line 13, file "Code")
我不确定我的代码有什么问题。我猜这与"headers" 部分有关,但我对 API 的了解还不够,无法确定。我正在使用这个测试项目来尝试了解有关 API 的更多信息。
【问题讨论】:
-
我怀疑你的问题是标题部分在做什么。您可以使用基本身份验证,也可以使用承载身份验证。你在做〜也许是基本的?这不是很清楚。我可能只是将您的标题更改为
Authorization : Bearer sk_test_xxx。我怀疑看起来像这样:{"headers":{"Authorization" : "Bearer " + apiKey}}
标签: javascript google-apps-script google-sheets stripe-payments