0

I have a problem with this reference From this Site Using Google SpreadSheet as Database. the problem is that. the Android Application cannot fetch the data in a google spreadsheet. The Application can successfully run but couldn't find data in the Spreadsheet.

I Already Updated the codes from the android studio because of the old version used codes. I just copy and paste it and change some of it.

Codes Below:

The Script Link to fetch the Data :

https://script.google.com/macros/s/AKfycbwZJCWoQ7dpC5KwyRM9JYsjCjymQUspAfPmniOApD_CSEoc-LdP/exec?id=16O_OfgKxASgqa2WWQKePJI1jnJMTdb4OyXbUJU6kWH0&sheet=Sheet1

Link of the SpreadSheet :

https://docs.google.com/spreadsheets/d/16O_OfgKxASgqa2WWQKePJI1jnJMTdb4OyXbUJU6kWH0/edit#gid=0

This is the App Script that Fetches the data:

you can also see the app script codes here : App Script Codes.

    function doGet(request) {
  var output  = ContentService.createTextOutput(),
      data    = {},
      id      = request.parameters.id,
      sheet   = request.parameters.sheet,
      ss      = SpreadsheetApp.openById(id);

  data.records = readData_(ss, sheet);

  var callback = request.parameters.callback;

  if (callback === undefined) {
    output.setContent(JSON.stringify(data));
  } else {
    output.setContent(callback + "(" + JSON.stringify(data) + ")");
  }
  output.setMimeType(ContentService.MimeType.JSON);

  return output;
}


function readData_(ss, sheetname, properties) {

  if (typeof properties == "undefined") {
    properties = getHeaderRow_(ss, sheetname);
    properties = properties.map(function(p) { return p.replace(/\s+/g, '_'); });
  }

  var rows = getDataRows_(ss, sheetname),
      data = [];

  for (var r = 0, l = rows.length; r < l; r++) {
    var row     = rows[r],
        record  = {};

    for (var p in properties) {
      record[properties[p]] = row[p];
    }

    data.push(record);

  }
  return data;
}


function getDataRows_(ss, sheetname) {
  var sh = ss.getSheetByName(sheetname);

  return sh.getRange(2, 1, sh.getLastRow() - 1, sh.getLastColumn()).getValues();
}


function getHeaderRow_(ss, sheetname) {
  var sh = ss.getSheetByName(sheetname);

  return sh.getRange(1, 1, 1, sh.getLastColumn()).getValues()[0];  
}

More Codes From the Link Above or click here for not scrolling back.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
RJ Berin
  • 13
  • 7
  • There are restrictions on the kind of data you can send between client and server. Check the section in the documentation on client server communications. For example you can’t send dates. – Cooper Nov 10 '18 at 21:26
  • If you are truly unable to send dates a possible workaround I can used is taking advantage of googles export links. You can read about it here. https://stackoverflow.com/questions/33713084/download-link-for-google-spreadsheets-csv-export-with-multiple-sheets. If you my your sheet readable to anyone with the link and never share the link its virtually impossible to guess. You can then use the instructions to retrieve part of the sheet. An added bonus is you don't have to waste your quota on retrieving information only setting it. – John Thompson Nov 10 '18 at 23:42

0 Answers0