내일 Google 캘린더 일정을 LINE Notify로 자동 알림
                                            
                                                
                                                
                                                
                                                
                                                
                                                 15790 단어  GoogleAppsScriptLineNotify
                    
아래 준비(LINE Notify 토큰 획득)
LINE측의 설정을 우선은 해 나갈 필요가 있습니다.
 아래 준비①
자신의 LINE을 열고 이메일 주소와 비밀번호를 설정하십시오.
※설정이 끝난 분은 수속 불필요
 iPhone의 경우
 
 Android의 경우
 
 아래 준비②
 LINE Notify 로 이동하여 로그인할 수 있는지 확인합니다.
 
 Google 스프레드 시트를 열고 스크립트 시트 열기 (컨테이너 바인드 스크립트)
새 스프레드시트 열기.
 
툴의 스크립트 에디터를 선택하면 아래와 같은 화면이 된다.
 
여기에 코드를 씁니다.
 소스 코드
code.js
// ここに発行したアクセストークンを書く
const token = "*********";
// ここにカレンダーIDとカレンダー名を書く。ここに書いたカレンダーのみリマインド対象になる
const calendarTitleMap = {
  "********@gmail.com" : "****のカレンダー",
  "********@group.v.calendar.google.com" : "****のカレンダー" // 例: "ja.va#[email protected]" : "バチカンのカレンダー"
};
const weekday = ["日", "月", "火", "水", "木", "金", "土"];
function notifyEvent() {
  const calendars = CalendarApp.getAllCalendars();
  let dt = new Date();// dateオブジェクトの生成
  dt.setDate(dt.getDate() + 1); //明日をdtにセット
  let tomorrow = Utilities.formatDate(dt, 'Asia/Tokyo', 'M/d(' + weekday[dt.getDay()] + ')');
  let message = `\n【明日${tomorrow}の予定】\n\n`;
  let dayText = "";
  // 取得した予定の数だけfor文でまわす
  for(i in calendars) {
    let calendar = calendars[i];
    let calendarName = calendarTitleMap[calendar.getId()]
    if ( calendarName == undefined ) {
      continue; // カレンダー名が設定されてなければパス
    }
    let events = calendar.getEventsForDay(dt);
    if( events.length == 0 ) {
      continue;
    }
    // カレンダー名を添えたい場合
    dayText += "< " + calendarName + " >\n";
    // イベントの数だけfor文でまわす
    for(e in events) {
      dayText += toDayText(events[e]);
    }
    dayText += "\n"
  }
  if ( dayText == "") {
      dayText += "予定はありません\n\n";
  }
  message += dayText;
  console.log(message);
  // LINE送信
  sendToLine(message);
}
function sendToLine(message){
  const options =
   {
     "method"  : "post",
     "headers" : {"Authorization" : "Bearer "+ token},
     "payload" : "message=" + message
   };
   UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}
function toDayText(event) {
  return toTimeText(event.getStartTime()) + ' - ' + toTimeText(event.getEndTime()) + " " + event.getTitle() + '\n';
}
function toTimeText(str){
  return Utilities.formatDate(str, 'Asia/Tokyo', 'HH:mm');
}
발행한 토큰과 적절한 이메일 주소를 입력하고 실행을 누르면 통지가 됩니다.
 
 날짜가 이상하다면
아래 설정을 변경하면 OK
(기본의 타임 존이 「GMT-05:00」으로 설정되어 있으므로, 일본 표준시인 「GMT+09:00」으로 설정할 필요가 있습니다)
 
파일에 새 appsscript.json가 새로 표시되므로 아래 코드로 변경
appsscript.json{
  "timeZone": "Asia/Tokyo",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}
 
 트리거 설정 예
매일 LINE에 알리기 위해 트리거 설정을 Google 측에서 설정할 수 있습니다.
예를 들어 매일 밤 오후 8시~9시에 내일 알림을 보내는 설정으로 설정하는 경우 아래 설정에서 트리거를 추가할 수 있습니다.
실행할 함수: notifyEvent
배포 시 실행: Head
이벤트 소스: 시간 수동형
시간 기반 트리거 유형: 날짜 기반 타이머
시간:오후 8시~9시
 
 해설
 용어 해설
새 스프레드시트 열기.

툴의 스크립트 에디터를 선택하면 아래와 같은 화면이 된다.

여기에 코드를 씁니다.
소스 코드
code.js
// ここに発行したアクセストークンを書く
const token = "*********";
// ここにカレンダーIDとカレンダー名を書く。ここに書いたカレンダーのみリマインド対象になる
const calendarTitleMap = {
  "********@gmail.com" : "****のカレンダー",
  "********@group.v.calendar.google.com" : "****のカレンダー" // 例: "ja.va#[email protected]" : "バチカンのカレンダー"
};
const weekday = ["日", "月", "火", "水", "木", "金", "土"];
function notifyEvent() {
  const calendars = CalendarApp.getAllCalendars();
  let dt = new Date();// dateオブジェクトの生成
  dt.setDate(dt.getDate() + 1); //明日をdtにセット
  let tomorrow = Utilities.formatDate(dt, 'Asia/Tokyo', 'M/d(' + weekday[dt.getDay()] + ')');
  let message = `\n【明日${tomorrow}の予定】\n\n`;
  let dayText = "";
  // 取得した予定の数だけfor文でまわす
  for(i in calendars) {
    let calendar = calendars[i];
    let calendarName = calendarTitleMap[calendar.getId()]
    if ( calendarName == undefined ) {
      continue; // カレンダー名が設定されてなければパス
    }
    let events = calendar.getEventsForDay(dt);
    if( events.length == 0 ) {
      continue;
    }
    // カレンダー名を添えたい場合
    dayText += "< " + calendarName + " >\n";
    // イベントの数だけfor文でまわす
    for(e in events) {
      dayText += toDayText(events[e]);
    }
    dayText += "\n"
  }
  if ( dayText == "") {
      dayText += "予定はありません\n\n";
  }
  message += dayText;
  console.log(message);
  // LINE送信
  sendToLine(message);
}
function sendToLine(message){
  const options =
   {
     "method"  : "post",
     "headers" : {"Authorization" : "Bearer "+ token},
     "payload" : "message=" + message
   };
   UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}
function toDayText(event) {
  return toTimeText(event.getStartTime()) + ' - ' + toTimeText(event.getEndTime()) + " " + event.getTitle() + '\n';
}
function toTimeText(str){
  return Utilities.formatDate(str, 'Asia/Tokyo', 'HH:mm');
}
발행한 토큰과 적절한 이메일 주소를 입력하고 실행을 누르면 통지가 됩니다.

날짜가 이상하다면
아래 설정을 변경하면 OK
(기본의 타임 존이 「GMT-05:00」으로 설정되어 있으므로, 일본 표준시인 「GMT+09:00」으로 설정할 필요가 있습니다)

파일에 새
appsscript.json가 새로 표시되므로 아래 코드로 변경appsscript.json
{
  "timeZone": "Asia/Tokyo",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

트리거 설정 예
매일 LINE에 알리기 위해 트리거 설정을 Google 측에서 설정할 수 있습니다.
예를 들어 매일 밤 오후 8시~9시에 내일 알림을 보내는 설정으로 설정하는 경우 아래 설정에서 트리거를 추가할 수 있습니다.
실행할 함수: notifyEvent
배포 시 실행: Head
이벤트 소스: 시간 수동형
시간 기반 트리거 유형: 날짜 기반 타이머
시간:오후 8시~9시
 
 해설
 용어 해설
용어 해설
사용하는 함수 설명
CalendarApp.getAllCalendars()
new Date()
.setDate()
.getDate()
Utilities.formatDate (인수 1, 인수 2, 인수 3)
getEventsForDay (날짜 객체)
작성중인 함수의 개요 설명
sendToLine()
toDayText()
toTimeText()
YouTube : htps: //같다. 베/우미 sぇ키 DpQ
Reference
이 문제에 관하여(내일 Google 캘린더 일정을 LINE Notify로 자동 알림), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/njn0te/items/9e7b1136cf5010dccbc3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)