我使用Google腳本來填充Google Analytics數據的Google Spreadsheet。
問題:我從我的電子表格文件中調用=getCountOfNewUsers(B1,B2)
時得到error: Login Required
。
注意:當我從谷歌腳本項目運行runTest()
一切工作正常。 供參考:我跟着this教程。從Google電子表格調用Google AnalyticsAPI時出現'需要登錄'錯誤
function runTest() {
try {
var results = getCountOfNewUsers(new Date(), new Date());
Logger.log(results.totalsForAllResults["ga:newVisits"]);
} catch(error) {
Logger.log(error.message);
}
}
function getCountOfNewUsers(date_from, date_till) {
date_from = Utilities.formatDate(date_from, 'GMT', 'yyyy-MM-dd');
date_till = Utilities.formatDate(date_till, 'GMT', 'yyyy-MM-dd');
var tableId = 'ga:*****';
// Make a request to the API.
var results = Analytics.Data.Ga.get(tableId, date_from, date_till, 'ga:newVisits', {});
if (results.getRows()) {
return results;
} else {
throw new Error('No views (profiles) found');
}
}
嗨Oleg - 我現在遇到了這個問題從單元格)。你有沒有找到解決方法? – bloo
原來,你不能從一個單元格函數中完成它:https://developers.google.com/apps-script/guides/sheets/functions#using_apps_script_services – bloo