如何在 Google 表格脚本中为 ssl-vp.com 提供 API 密钥?
How to provide an API key for ssl-vp.com in a Google Sheets script?
我正在尝试从 URL 获取 JSON 数据并将数据插入 Google 表格中。问题是当我尝试获取数据时这个响应我那个错误:
Error in the request for the returned code 401 of https://ssl-vp.com/rest/v1/Campaigns/1236223656534991/Recipients?by=ExternalId&page=1&itemsPerPage=500. Truncated server response: Unauthorized Cannot get campaign contacts (use the muteHttpExceptions option to examine the entire response) (line 15, file "Código")
我尝试在 URL 中插入 API KEY 但响应是相同的错误
function myFunction(){
var url = "https://ssl-vp.com/rest/v1/Campaigns/1236223656534991/Recipients?by=ExternalId&page=1&itemsPerPage=500";
var apiKey = "xxxxxxxxxxxxxxxxxxxxx";
var header={
"headers":{
"X-API-KEY":apiKey
}
};
var response = UrlFetchApp.fetch(url,header);
Logger.log(response.getContentText());
}
根据 ssl-vp.com's API docs,此服务需要 Authorization
header 中的 API 键,如下所示:
Authorization: Bearer <API_KEY>
将您的代码更改为:
var header = {
"headers": {
"Authorization": "Bearer " + apiKey
}
};
我正在尝试从 URL 获取 JSON 数据并将数据插入 Google 表格中。问题是当我尝试获取数据时这个响应我那个错误:
Error in the request for the returned code 401 of https://ssl-vp.com/rest/v1/Campaigns/1236223656534991/Recipients?by=ExternalId&page=1&itemsPerPage=500. Truncated server response: Unauthorized Cannot get campaign contacts (use the muteHttpExceptions option to examine the entire response) (line 15, file "Código")
我尝试在 URL 中插入 API KEY 但响应是相同的错误
function myFunction(){
var url = "https://ssl-vp.com/rest/v1/Campaigns/1236223656534991/Recipients?by=ExternalId&page=1&itemsPerPage=500";
var apiKey = "xxxxxxxxxxxxxxxxxxxxx";
var header={
"headers":{
"X-API-KEY":apiKey
}
};
var response = UrlFetchApp.fetch(url,header);
Logger.log(response.getContentText());
}
根据 ssl-vp.com's API docs,此服务需要 Authorization
header 中的 API 键,如下所示:
Authorization: Bearer <API_KEY>
将您的代码更改为:
var header = {
"headers": {
"Authorization": "Bearer " + apiKey
}
};