craftApprentice
craftApprentice

Reputation: 2777

How to use Google suggested queries API in Google Apps Script

Is there a way to use Google suggested queries API in Google Apps Script? If the answer is no, what is be best alternative? My aim is to perform spell correction and semantic aproximation for poor queries keywords of values in a spreadsheet.

Upvotes: 0

Views: 966

Answers (1)

AshClarke
AshClarke

Reputation: 3078

You can use the UrlFetchApp to get the data.

  var query = "give me suggestions"
  var stringResponse = UrlFetchApp.fetch("http://suggestqueries.google.com/complete/search?client=firefox&q=" + encodeURIComponent(query)).getContentText();
  var parsedResponse = JSON.parse(stringResponse);
  var searchString = parsedResponse[0];
  Logger.log("search string: " + searchString);
  var suggestions = parsedResponse[1];
  for (var i=0; i<suggestions.length; i++) {
    Logger.log("Suggestion: " + suggestions[i]);
  }

Upvotes: 2

Related Questions