Skip to content

Instantly share code, notes, and snippets.

@rhyskentish
Created October 4, 2019 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhyskentish/17c6d30a7f0eb72d8991faf36e0ef387 to your computer and use it in GitHub Desktop.
Save rhyskentish/17c6d30a7f0eb72d8991faf36e0ef387 to your computer and use it in GitHub Desktop.
function getLatestReviews() {
var token = Goth.getToken('PlayConsole')
var response = UrlFetchApp.fetch("https://www.googleapis.com/androidpublisher/v3/applications/your_package_name/reviews?access_token=your_auth_token");
// Parse the JSON reply
var json = response.getContentText();
var data = JSON.parse(json);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var reviews = data["reviews"].reverse()
var lastRow = sheet.getLastRow();
var reviewIdsDouble = sheet.getRange(3, getColByName("Review ID"), lastRow, 1).getValues(); //getRange(starting Row, starting column, number of rows, number of columns)
var reviewIds = [].concat.apply([], reviewIdsDouble);
reviews.forEach(function(elem,i) {
if(reviewIds.indexOf(elem["reviewId"]) == -1) {
lastRow = sheet.getLastRow() + 1
var userComment = elem["comments"][0]["userComment"]
sheet.getRange(lastRow, getColByName("Version Number")).setValue(userComment["appVersionName"]);
var t = new Date(1970, 0, 1); // Epoch
t.setSeconds(userComment["lastModified"]["seconds"]);
sheet.getRange(lastRow, getColByName("Date Of Review")).setValue(t);
sheet.getRange(lastRow, getColByName("Review Rating")).setValue(userComment["starRating"]);
sheet.getRange(lastRow, getColByName("Cumalative Ave")).setFormula("=AVERAGE($D$3:D"+lastRow+")")
sheet.getRange(lastRow, getColByName("Comment")).setValue(userComment["text"]);
sheet.getRange(lastRow, getColByName("Device")).setValue(userComment["deviceMetadata"]["productName"]);
sheet.getRange(lastRow, getColByName("Android OS")).setValue(userComment["androidOsVersion"]);
sheet.getRange(lastRow, getColByName("Review ID")).setValue(elem["reviewId"])
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment