本文介绍了参数(字符串,数字)与getRange()的方法签名不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个脚本来从Google Analytics(分析)中获取数据.我在许多网站和youtube视频的帮助下编写了此文件,但无法解决我的代码中的1个问题.
I am trying to write a script to fetch data from Google Analytics. I wrote this using help from lots of sites and youtube videos but unable to fix 1 issue in my code.
function myFunction() { var app = SpreadsheetApp var doc = app.getActiveSpreadsheet().getActiveSheet(); for(var i=0;i<107;i++){ var viewId = doc.getRange(i+2,1).getValue(); // Your Google Analytics view ID var startDate = Utilities.formatDate(doc.getRange("K1").getValue(), "GMT+2", "yyyy-MM-dd"); var endDate = Utilities.formatDate(doc.getRange("K2").getValue(), "GMT+2", "yyyy-MM-dd");; var metric = 'ga:sessions, ga:newUsers, ga:bounceRate'; var option = {'segment': 'gaid::reM9CWAgR0ys4_Ng4N_aVw'}; var result = Analytics.Data.Ga.get(viewId, startDate, endDate, metric, option); // Make the request var sessions = result.totalsForAllResults['ga:sessions']; var newusers = result.totalsForAllResults['ga:newUsers']; var bouncerate = result.totalsForAllResults['ga:bounceRate']; var doc = app.getActiveSpreadsheet(); // Current document var sheet = doc.getActiveSheet(); // Current sheet sheet.getRange(i+2,2,1,1).setValue(sessions); // Write total sessions sheet.getRange(i+2,3,1,1).setValue(newusers); // Write toal newusers sheet.getRange(i+2,4,1,1).setValue(bouncerate); // Write total bouncerate } }推荐答案
一旦我更改了工作表中的视图ID,此问题就会自动解决.我想问题出在视图ID
This Got auto resolved once I changed the View ID in my sheet. I guess the problem was with view ID
更多推荐
参数(字符串,数字)与getRange()的方法签名不匹配
发布评论