0
我有這個javascript來提取html表格,然後將數組作爲參數傳遞給google應用程序腳本。從另一個Google帳戶執行Google Apps腳本時出現403錯誤
var CLIENT_ID = 'some ID';
var SCRIPT_ID = 'some ID';
var SCOPES = ['https://www.googleapis.com/auth/drive.file'];
function handleAuthClick(event) {
gapi.auth.authorize(
{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true},
handleAuthResult);
}
function handleAuthResult(authResult) {
if (authResult) {
// Access token has been successfully retrieved, requests can be sent to the API
} else {
// No access token could be retrieved, force the authorization flow.
gapi.auth.authorize(
{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': false},
handleAuthResult);
}
}
function exportGsheet() {
var myTableArray = [];
$("table#fin tr").each(function() {
var arrayOfThisRow = [];
var tableData = $(this).find('td');
if (tableData.length > 0) {
tableData.each(function() { arrayOfThisRow.push($(this).text()); });
myTableArray.push(arrayOfThisRow);
}
});
var params = JSON.stringify(myTableArray);
var request = {
'function': 'setData',
'parameters': params,
'devMode': true // Optional.
};
var op = gapi.client.request({
'root': 'https://script.googleapis.com',
'path': 'v1/scripts/' + SCRIPT_ID + ':run',
'method': 'POST',
'body': request
});
op.execute(function(resp){opensheet(resp)});
}
以下是應用程序腳本。這使用Drive API和可執行API。
var DOC_ID = 'some id';
var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
var folder = DriveApp.getFolderById('some id');
function setData(parameters) {
var getFile = DriveApp.getFileById(DOC_ID);
var file = getFile.makeCopy(formattedDate, folder);
var ss = SpreadsheetApp.open(file);
var ssId = ss.getId();
ss.getSheets()[0].getRange(5,1,50,24).clear();
var e = JSON.parse(parameters);
var outerArray = [];
for(var i = 0; i < e.length; i++) {
outerArray.push(e[i]);
}
ss.getSheets()[0].getRange(5, 2, outerArray.length, outerArray[0].length).setValues(outerArray);
return {"url":ssId};
Logger.log(ssId);
}
當我授權使用擁有應用程序腳本和項目(我自己的gmail帳戶)的gmail ID時,一切正常。但是,當我進行身份驗證使用不同的Gmail帳戶,我得到下面的錯誤:
error: {code: 403, message: "The caller does not have permission", status: "PERMISSION_DENIED"}
code: 403
message: "The caller does not have permission"
status: "PERMISSION_DENIED"
我打算讓這個應用程序公開,任何人都應該能夠使用其Gmail帳戶進行身份驗證,並執行腳本。我怎麼做?請幫忙。
文件與ID文件應公開閱讀 –
其已公開。後來我明白我必須在Developer Console Project下提供許可。轉到'項目權限 - 權限 - xxx' - 添加成員' - 然後添加域或電子郵件ID。添加的電子郵件ID /域將能夠執行該腳本。但是,我沒有能夠太gmail域名。我提出了[問題](https://code.google.com/p/google-apps-script-issues/issues/detail?id=5930&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component% 20Owner)與谷歌支持 – Maddy