I'm running the below script that will read from google sheets but is failing with the error"
Invalid Value (line 5, file "Code")
function GetShortUrlClicks() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
for (var i = 0; i < data.length; i++){
var analytics = UrlShortener.Url.get(data ,{projection:'FULL'}).getAnalytics();
var clicks = analytics.getAllTime();
Logger.log(clicks)
}
}
However, if I run the same script with a URL in place of data the script runs and I get the proper data back working the Google URL API that equals to the amount of cells I have in the Google Sheet.
function GetShortUrlClicks() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
for (var i = 0; i < data.length; i++){
var analytics = UrlShortener.Url.get('google.com',{projection:'FULL'}).getAnalytics();
var clicks = analytics.getAllTime();
Logger.log(clicks)
}
}
I'm assuming the data variable is not getting passed properly.
答案 0 :(得分:0)
使用以下更新。
var analytics = UrlShortener.Url.get(data[i],{projection:'FULL'}).getAnalytics();