- Create a new Google Sheets file
- Go to Extensions → Apps Script
- Remove all the code and copy-paste the following instead
- Save your project and go back to your sheet
- Enter main keywords in column
- Create a drawing button an assign the script keywordSuggestions and name it "Run"
- Click the run button to get the suggestions in column
- When you run, it requires app script permission
- Once you grant access the result will show in column B
The code to paste in Apps Script inside Google Sheets:
function keywordSuggestions() {
var sheet = SpreadsheetApp.getActiveSheet();
var keywords = sheet.getRange("A2:A").getValues();
for (var i = 0; i < keywords.length; i++) {
if (keywords[i][0] == "") {
continue;
}
var suggestions = getGoogleSuggestions(keywords[i][0]);
sheet.getRange(i + 2, 2).setValue(suggestions.join(", "));
}
}
function getGoogleSuggestions(keyword) {
var suggestions = [];
var url = "http://suggestqueries.google.com/complete/search?client=firefox&q=" + keyword;
var response = UrlFetchApp.fetch(url);
var json = JSON.parse(response.getContentText());
for (var i = 0; i < json[1].length; i++) {
suggestions.push(json[1][i]);
}
return suggestions;
}