Invalid request (Google::Apis::ClientError) 404

Viewed 450

we are using this api for getting spreadsheet datas.

Until 2 days ago we could get data from spreadsheet by using this api but since yesterday i can't.

then to investigate this problem, i put some debug log to http_command.rb#check_status at my local.

it says

---check_status----
10:07:20 web.1           | D, [2021-08-13T10:07:20.929125 #71084] DEBUG -- : 404
10:07:20 web.1           | D, [2021-08-13T10:07:20.929163 #71084] DEBUG -- : #<HTTP::Message::Headers:0x00007ff3d5c60360 @http_version="1.1", @body_size=0, @chunked=false, @request_method="GET", @request_uri=#<Addressable::URI:0x3ff9eae30e1c URI:https://spreadsheets.google.com/feeds/worksheets/1IQiTTQGp2mJnBC_12IFWzfluDIVbO61E57ZifPBZcMA/private/full?>, @request_query=nil, @request_absolute_uri=nil, @status_code=404, @reason_phrase="Not Found", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:UTF-8>, @is_request=false, @header_item=[["Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"], ["Pragma", "no-cache"], ["Expires", "Mon, 01 Jan 1990 00:00:00 GMT"], ["Date", "Fri, 13 Aug 2021 01:07:20 GMT"], ["Content-Type", "text/html; charset=utf-8"], ["Content-Encoding", "gzip"], ["P3P", "CP=\"This is not a P3P policy! See g.co/p3phelp for more info.\""], ["x-chromium-appcache-fallback-override", "disallow-fallback"], ["X-Content-Type-Options", "nosniff"], ["X-XSS-Protection", "1; mode=block"], ["Server", "GSE"], ["Set-Cookie", "NID=221=rqH2hzFR3iFWy-QWMGVoa8dH7hjJzmg2N5ulckb26slyJbGJL2c7ftBeWYC3iUv7Wa6w0xhVO-pmZHGhkLPeOWgZo9PcoBi1z-qr71ecMIwCOyHoJgCbnx1iJphjJsfgwNGxrLHaQ58p4gfc260wq4KmVabCRH8idZe5Z62iLOc; expires=Sat, 12-Feb-2022 01:07:20 GMT; path=/; domain=.google.com; HttpOnly"], ["Alt-Svc", "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""], ["Transfer-Encoding", "chunked"]], @dumped=false>
10:07:20 web.1           | D, [2021-08-13T10:07:20.929357 #71084] DEBUG -- : <!DOCTYPE html><html lang="ja"><head><meta name="description" content="ウェブ ワープロ、プレゼンテーション、スプレッドシート"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"><link rel="shortcut icon" href="//docs.google.com/favicon.ico"><title>ページが見つかりません</title><meta name="referrer" content="origin"><link href="//fonts.googleapis.com/css?family=Product+Sans" rel="stylesheet" type="text/css" nonce="C5LZHC1OaGxvub1TlKvZ5g"><style nonce="C5LZHC1OaGxvub1TlKvZ5g">/* Copyright 2021 Google Inc. All Rights Reserved. */

what happened?

api limitation?

i checked i don access this api over api limitaion.

1 Answers

I am having a very similar issue from a day ago as well. This occurred as well about 8 months ago and was a bug in a new Google deployment that took a week or so to resolve. The way around this is to create a txt file and update via a scheduled script.

The first function replaces a text file, that is it. You need to uncomment the line below the catch //folder.createFile(filename, data); when you run this to create the initial file. The then want to comment it out because occasionally Google can't find the file (irony what!)

function updateFile (folder, filename, data) {
  try {
    // filename is unique, so we can get first element of iterator
    var file = folder.getFilesByName(filename).next();
    file.setContent(data);
} catch(e) {
    //folder.createFile(filename, data);
   var strBody =  'oops....  ';
MailApp.sendEmail('xxx.yyy@com', 'Issue with file update - cannot find file',strBody);
Logger.log(strBody);
}

}

The second function is the one you call from your scheduled agent. Use your orignal URL in the var url='xxx'; line. Opening the current spreadsheet is used to get your folder that the sheet is in, nothing else.

function storeTestingTable() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("your-tab-name"); 
  var folder = DriveApp.getFileById(ss.getId()).getParents().next();
  var fileName = "your-csv.csv";
  var url = "https://spreadsheets.google.com/feeds/list/{id}/1/public/values?alt=json-in-script" ;  // whatever your original request was...
  var token = ScriptApp.getOAuthToken();  
  var response = UrlFetchApp.fetch(url , {
    headers: {
      'Authorization': 'Bearer ' +  token
    }
  });
  Logger.log('Export File Size: ' + response.getBlob().getDataAsString().length);

  if (response.getBlob().getDataAsString().length > 500) {
    updateFile(folder,fileName,response.getBlob().getDataAsString());
   } else {
  Logger.log("Very low string size please investigate - file not replaced: " + response.getBlob().getDataAsString().length);
  }
}
Related