Google社のスプレッドシートのドキュメントバインドされたGoogle Appscriptでは、スプレッドシートの行をGoogleカレンダーの予定に変えるスクリプトを作成しました。私の同僚は、カレンダーを編集したり共有権限を変更する権限を持っていても、私の同僚にとってはうまく機能しませんでした。同僚は、calendar.google.comからカレンダーに予定を作成できることを証明しました。Google Apps Scriptはシートからカレンダーイベントを作成できませんか?
彼は、スクリプト実行時に彼は、次のエラーメッセージが表示されます。
{"message":"Forbidden","name":"GoogleJsonResponseException","fileName":"SCHEDULER","lineNumber":204,"stack":"\tat SCHEDULER:204 (createAppointments)\n"}
ライン204は、コマンドに対応:
Calendar.Events.insert(event, CAL, {sendNotifications: true, supportsAttachments:true});
彼はに編集権限を持っている場合カレンダー、なぜこれは禁じられていますか? Google Apps Scriptのカレンダーサービスに問題はありますか?さらに、CAL変数を私が個人的に作成したカレンダーに変更し、同じ権限で彼に共有しました。彼はそのカレンダーをうまく編集できます。ここで
は機能
function createAppointments() {
var CAL = '[email protected].com';
for(/*each row in spreadsheet*/)
{
if(/*needs appointment*/)
{
var object = {/*...STUFF...*/};
var coworker = '[email protected]';
var timeArgs = {start: /*UTC Formatted time*/, end: /*UTC Formatted time*/}
if(/*All the data checks out*/{
var summary = 'Name of appointment'
var notes = 'Stuff to put in the body of the calendar appointment';
var location = '123 Happy Trail, Monterrey, TX 12345'
//BUILD GOOGLE CALENDAR OBJECT
var event = {
"summary": summary,
"description": notes,
"start": {
"dateTime": timeArgs.start,
"timeZone": TZ
},
"end": {
"dateTime": timeArgs.end,
"timeZone": TZ
},
"guestsCanInviteOthers": true,
"reminders": {
"useDefault": true
},
"location": location
//,"attendees": []
};
event.attendees = [{[email protected], displayName: 'coworker name'}];
//CREATE CALENDAR IN GOOGLE CALENDAR OF CONST CAL
Calendar.Events.insert(event, CAL, {sendNotifications: true, supportsAttachments:true});
} else{/*Tell user to fix data*/}
}
}
のための擬似コードはどうもありがとうございました!
アップデート2017年12月29日:
私はジェイソンAllshornとクレイジーイヴァンに応じてアプリを調整しようとしました。あなたの助けをありがとう、これまでのところ!興味深いことに、私は、Advanced Calendar ServiceとCalendarAppの両方を使用して同じレスポンスを実行しました。以下に示すように
エラーは、次のとおりです。
<!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Error</title><style type="text/css">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style="margin:20px"><div><img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png"></div><div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">Object does not allow properties to be added or changed.</div></body></html>
または、HTMLエディタを使用しているを解析した後:
ことも何を意味するのでしょうか?私は高度なサービスを有効にしており、スクリプトは誰でも実行できるようになっています。何か案は?
私は、calendarapp/Advanced Calendarイベント作成コマンドを実行しようとした後にエラーが戻ってきたことをテストした後で確認しました。ここで
は私がはるかにこれを取得させた私のコードです:
function convertURItoObject(url){
url = url.replace(/\+/g,' ')
url = decodeURIComponent(url)
var parts = url.split("&");
var paramsObj = {};
parts.forEach(function(item){
var keyAndValue = item.split("=");
paramsObj[keyAndValue[0]] = keyAndValue[1]
})
return paramsObj; // here's your object
}
function doPost(e) {
var data = e.postData.contents;
data = convertURItoObject(data);
var CAL = data.cal;
var event = JSON.parse(data.event);
var key = data.key;
var start = new Date(event.start.dateTime);
if(ACCEPTEDPROJECTS.indexOf(key) > -1)
{
try{
var calendar = CalendarApp.getCalendarById(CAL);
calendar.createEvent(event.summary, new Date(event.start.dateTime), new Date(event.end.dateTime), {description: event.description, location: event.location, guests: event.guests, sendInvites: true});}
/*try {Calendar.Events.insert(event, CAL, {sendNotifications: true, supportsAttachments:true});} Same error when I use this command*/
catch(fail){return ContentService.createTextOutput(JSON.stringify(fail));}
e.postData.result = 'pass';
return ContentService.createTextOutput(JSON.stringify(e));
}
else {
return ContentService.createTextOutput('Execution not authorized from this source. See CONFIG of target project for details.');
}
}