Better API Key Storage in Google Sheets | API Development | TO…
Better API Key Storage in Google Sheets
  • NUKE Calchas [2579182]Calchas [2579182]
    • Calchas [2579182]
    • Role: Civilian
    • Level: 51
    • Posts: 14
    • Karma: 9
    • Last Action: 44 minutes
    • Quote
    • Report
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Thread created on 23:47:26 - 24/06/21 (4 months ago)
    |
    Last replied 06:55:29 - 26/06/21 (4 months ago)
    When writing a Google Sheet that uses the Torn API it's better to store the API key as a property of the sheet rather than in the sheet itself.

    Some advantages of this technique are:
    • You don't show the API key anywhere
    • Making a copy of the sheet clears the properties, you don't have to worry about clearing old API Keys
    • You are prompted to enter your API Key, users cannot forget to do it
    My getApi function is:


    function getApiKey() {
    var scriptProperties = PropertiesService.getScriptProperties();

    var key = scriptProperties.getProperty("API_KEY");

    if ((key == null) || (key == '')) {
    var ui = SpreadsheetApp.getUi();
    var response = ui.prompt('Enter API Key');

    if (response.getSelectedButton() == ui.Button.OK) {
    key = response.getResponseText();
    scriptProperties.setProperty('API_KEY',key);
    }
    }
    return key;
    }



    More information about the Google Apps Property Service can be found at developers.google.com
  •   Father [2131687]Father [2131687]
    • Father [2131687]
    • Role: Civilian
    • Level: 81
    • Posts: 1223
    • Karma: 3737
    • Last Action: 11 minutes
    • Quote
    • Report
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 12:40:59 - 25/06/21 (4 months ago)
    Post link copied to clipboard Copy post link
    Does UI or Prompt work on mobile?

    I am mostly on mobile and do all the App Scripts related stuff on mobile. I already use Properties to store my Api key in my personal scripts. But I am not sure prompt would work on mobile, unless I force the browser to Desktop Mode which is clunky af.
    Last edited by Father on 12:41:20 - 25/06/21
  • PM Helcostr [1934501]Helcostr [1934501]
    • Helcostr [1934501]
    • Role: Wiki Editor
    • Level: 15
    • Posts: 2787
    • Karma: 1367
    • Last Action: 7 hours
    • Quote
    • Report
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 06:55:29 - 26/06/21 (4 months ago)
    Post link copied to clipboard Copy post link
    This is a very important security feature. Good article.
Reply
Thread Title: