为什么在连接到我自己的数据源时看不到 API 键提示?
Why can't I see API Key prompt when connecting to my own data source?
我无法弄清楚为什么我看不到输入 API 键的提示。我可以直接连接而无需任何身份验证。为什么 API 键被忽略了?
auth.js 文件:
function getAuthType() {
return {
type: 'KEY'
};
}
function validateKey(key) {
var url = 'http://myapi.com/endpoint?api_key=' + key;
var options = {
"method": "post",
"contentType":"application/json"
};
var response = JSON.parse(
UrlFetchApp.fetch(url, options)
);
Logger.log(response.data.length > 0)
return response.data.length > 0;
}
function isAuthValid() {
var userProperties = PropertiesService.getUserProperties();
var key = userProperties.getProperty('dscc.key');
return validateKey(key);
}
function resetAuth() {
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('dscc.key');
}
function setCredentials(request) {
var key = request.key;
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('dscc.key', key);
return {
errorCode: 'NONE'
};
}
function isAdminUser() {
return false;
}
Logger.log
输出:
我使用的是 http
url。我们已将 API 移至 https
,问题已解决。 Data Studio 不显示任何错误消息并跳过授权步骤。这很奇怪。
编辑: 一个月后,在查看文档时我注意到 Data Studio 已经在要求我们 https
url.
Each prefix must use https://
, not http://
. source
我无法弄清楚为什么我看不到输入 API 键的提示。我可以直接连接而无需任何身份验证。为什么 API 键被忽略了?
auth.js 文件:
function getAuthType() {
return {
type: 'KEY'
};
}
function validateKey(key) {
var url = 'http://myapi.com/endpoint?api_key=' + key;
var options = {
"method": "post",
"contentType":"application/json"
};
var response = JSON.parse(
UrlFetchApp.fetch(url, options)
);
Logger.log(response.data.length > 0)
return response.data.length > 0;
}
function isAuthValid() {
var userProperties = PropertiesService.getUserProperties();
var key = userProperties.getProperty('dscc.key');
return validateKey(key);
}
function resetAuth() {
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('dscc.key');
}
function setCredentials(request) {
var key = request.key;
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('dscc.key', key);
return {
errorCode: 'NONE'
};
}
function isAdminUser() {
return false;
}
Logger.log
输出:
我使用的是 http
url。我们已将 API 移至 https
,问题已解决。 Data Studio 不显示任何错误消息并跳过授权步骤。这很奇怪。
编辑: 一个月后,在查看文档时我注意到 Data Studio 已经在要求我们 https
url.
Each prefix must use
https://
, nothttp://
. source