//友だち数を取得する
function doGetfriendsnumber() {
varTokensheet = SpreadsheetApp.openById("スプレッドシートID").getSheetByName("シート名");//各店のチャネルトークンが載ったシート
varchannel_tokenarray = Tokensheet.getDataRange().getValues();//トークンを2次元配列を取得
//取得した友だち数を入力するシート
varspreadsheet = SpreadsheetApp.getActiveSpreadsheet();
varsheet =spreadsheet.getSheetByName("データ");
varlastrow = sheet.getLastRow();
//取得の日付とアップロードの日付
vardate1 = Utilities.formatDate(newDate(),"Asia/Tokyo","yyyyMMdd");
varuploaddate = Utilities.formatDate(newDate(),"Asia/Tokyo","yyyy/MM/dd");
vary = newDate().getFullYear();
varm = newDate().getMonth();
vard = newDate().getDate();
//ここから友だち数の取得
varARRAY = [];
for(variinchannel_tokenarray){
varstorename = channel_tokenarray[i][0]; //1列目に店舗名
varchannel_token = channel_tokenarray[i][1];//2列めにトークン
if(channel_token == "" || storename == ""){
continue;
}
//一応加工
vardate1 = Utilities.formatDate(newDate(y,m,d),"Asia/Tokyo","yyyyMMdd");
vardate2 = Utilities.formatDate(newDate(y,m,d),"Asia/Tokyo","yyyy/MM/dd");
varurl = "https://api.line.me/v2/bot/insight/followers?date=" + date1;
varoptions = {
"method" : "get",
"headers" : {
"Authorization" : "Bearer " + channel_token,
},
"muteHttpExceptions" : true,
"validateHttpsCertificates" : false,
"followRedirects" : false
};
var res = UrlFetchApp.fetch(url, options);
var json = JSON.parse(res.getContentText());
var values = Object.values(json);
var array = Object.entries(values);
//取得したデータを2次元配列に加工
var dataarray = [uploaddate,date2,storename,array[1][1],array[2][1],array[3][1]];
ARRAY.push(dataarray);
}
sheet.getRange(lastrow+1,1,ARRAY.length,ARRAY[0].length).setValues(ARRAY);//シートに貼り付け
}