Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

node.js - Web App call fails with "... Error code INTERNAL" with Custom API

I have a spreadsheet with a collection of cards, and I wrote a doGet() function to pick a random one, and return it to the user. When entering the Web App url into a web browser, the result appears fine. However, when I try to make a HTTP Get request through the request module, it returns this:

<!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">We&#39;re sorry, a server error occurred while reading from storage. Error code INTERNAL.</div></body></html>

Extracted error message is:

We're sorry, a server error occurred while reading from storage. Error code INTERNAL.

I googled this error code, but nobody's had the same ending of "Error code INTERNAL", and most were about other users. Here is my doGet function and request function

Google Apps Script:

function doGet(request){
  var requestType = request.parameter.type
  if(requestType == "random_card"){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
    var entriesL = sheet.getLastRow() - 1;
    var cardNum = getRandomInt(entriesL);
    var card = SpreadsheetApp.getActiveSheet().getRange(2 + cardNum, 2).getValue();
    var set = SpreadsheetApp.getActiveSheet().getRange(2 + cardNum, 1).getValue();
    var output = '{"card":"' + card + '","cardSet":"' + set + '"}';
    Logger.log(output)
    return ContentService.createTextOutput(output);
  }
}

Node.js

function randomCard(){
  var info;
  request.get('{url here}?action=get&type=random_card',function(err,res,body){
    console.log(body)
    info = JSON.parse(body);
  });

  return info;
}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yep, this should be enough. The error is indicative of the permission error (since you call the webapp externally - although you should've got the permission before as the requirement is the same with getActiveSpreadsheet) - try opening the web app in script editor, run the function in question and authorize it. If you already did so, check if the web app is configured to run "as me" (if you are ok with that) or consider switching to the Sheets API – Oleg Valter


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...