Api 社区连接器“;回应";及;requestedFields";没有定义
我正在构建一个从Google Data Studio到SpyFu API的社区连接器 我将我的代码与CommunityConnector教程进行了比较,它看起来不错,但关键变量仍然没有定义,即使在进行API调用之后也是如此 直到我开始使用正确的API请求格式运行live API请求(从清单部署)之后,这个错误才出现。为了澄清这一点,当我尝试将API数据添加到我的Google data Studio时,会出现此错误 错误:TypeError:无法调用未定义的方法“map”。 显然,“response”和“requestedFields”没有定义。我不知道为什么 来自script.google.comApi 社区连接器“;回应";及;requestedFields";没有定义,api,google-apps-script,google-data-studio,Api,Google Apps Script,Google Data Studio,我正在构建一个从Google Data Studio到SpyFu API的社区连接器 我将我的代码与CommunityConnector教程进行了比较,它看起来不错,但关键变量仍然没有定义,即使在进行API调用之后也是如此 直到我开始使用正确的API请求格式运行live API请求(从清单部署)之后,这个错误才出现。为了澄清这一点,当我尝试将API数据添加到我的Google data Studio时,会出现此错误 错误:TypeError:无法调用未定义的方法“map”。 显然,“respons
我已经尝试更改映射到的变量,但在这里没有任何进展。任何帮助都将不胜感激。当我在调试连接器时遇到问题时,我通常会先添加这个helper函数,然后在不同的地方调用它,看看到底哪里出了问题函数logObject(object){cc.newDebugError().setText(JSON.stringify(s)).throwException();}``谢谢您的帮助。我刚刚使用完Community Connector,但它只打印了模式中4个信息字段中的2个。知道如何确保getData()请求包含其请求中的所有字段吗?它似乎只自动使用前两个维度和度量。发送到getData()的请求字段取决于图表的配置方式。如果希望请求所有字段,请创建一个表,并手动向其中添加所有维度和度量。当我在调试连接器时遇到问题时,我通常会首先添加此帮助器函数,并在不同的位置调用它,以查看到底哪里出了问题函数logObject(object){cc.newDebugError().setText(JSON.stringify(s)).throwException();}``谢谢您的帮助。我刚刚使用完Community Connector,但它只打印了模式中4个信息字段中的2个。知道如何确保getData()请求包含其请求中的所有字段吗?它似乎只自动使用前两个维度和度量。发送到getData()的请求字段取决于图表的配置方式。如果希望请求所有字段,请创建一个表,并手动向其中添加所有维度和度量。
function getAuthType() {
var response = {
type: 'NONE'
};
return response;
}
function getConfig(request) {
var cc = DataStudioApp.createCommunityConnector();
var config = cc.getConfig();
config.newInfo()
.setId('instructions')
.setText('Give me SpyFu information on the following domain:');
config.newTextInput()
.setId('domain')
.setName('Enter the domain to search')
.setHelpText('e.g. ebay.com')
.setPlaceholder('ebay.com');
config.newTextInput()
.setId('SECRET_KEY')
.setName('Enter your API Secret Key')
.setHelpText('e.g. A1B2C3D4')
.setPlaceholder('A1B2C3D4');
//config.setDateRangeRequired(true);
return config.build();
}
function getFields(request) {
var cc = DataStudioApp.createCommunityConnector();
var fields = cc.getFields();
var types = cc.FieldType;
fields.newDimension()
.setId('Keyword')
.setName('Keywords')
.setDescription('The keywords most often attributed to this domain.')
.setType(types.TEXT);
fields.newMetric()
.setId('Rank')
.setName('Rankings')
.setDescription('The ranking of the target site keyword on the Google Search Page.')
.setType(types.NUMBER);
fields.newMetric()
.setId('Monthly_Searches')
.setName('Searches per Month')
.setDescription('Number of times people have searched for this term within in the last month.')
.setType(types.NUMBER);
return fields;
}
function getSchema(request) {
var fields = getFields(request).build();
return { schema: fields };
}
function responseToRows(requestedFields, response) {
return response.map(function(Array) {
var row = [];
requestedFields.asArray().forEach(function (field) {
switch (field.getId()) {
case 'Keyword':
return row.push(Array.term);
case 'Rank':
return row.push(Array.position);
case 'Monthly_Searches':
return row.push(Array.exact_global_monthly_search_volume);
default:
return row.push('');
}
});
return { values: row };
});
}
function getData(request) {
var requestedFieldIds = request.fields.map(function(field) {
return field.name;
});
var requestedFields = getFields().forIds(requestedFieldIds);
// Fetch data from API
var url = [
'https://www.spyfu.com/apis/url_api/organic_kws?q='
+ request.configParams.domain
+ '&r=10'
+ '&api_key='
+ request.configParams.SECRET_KEY
];
try {
var response = UrlFetchApp.fetch(url.join(''));
} catch (e) {
DataStudioApp.createCommunityConnector()
.newUserError()
.setDebugText('Failed URL Fetch Attempt. Exception details: ' + e)
.setText('There was an error accessing this domain. Try again later, or file an issue if this error persists.')
.throwException();
}
try {
var parsedResponse = JSON.parse(response).downloads;
} catch (e) {
DataStudioApp.createCommunityConnector()
.newUserError()
.setDebugText('Error parsing the JSON data. Exception details: ' + e)
.setText('There was an error parsing the JSON data. Try again later, or file an issue if this error persists.')
.throwException();
}
var rows = responseToRows(requestedFields, parsedResponse);
return {
schema: requestedFields.build(),
rows: rows
};
}