简体   繁体   中英

Google sheets - Json to Sheet

I'm using this Google App script

   // Reference: https://www.labnol.org/code/20068-blogger-api-with-google-apps-script

function bloggerAPI() {

      var api = "https://www.googleapis.com/blogger/v3/users/self/blogs";

      var headers = {
        "Authorization": "Bearer " + getService().getAccessToken()
      };

      var options = {
        "headers": headers,
        "method" : "GET",
        "muteHttpExceptions": true
      };

      var response = UrlFetchApp.fetch(api, options);

      var json = JSON.parse(response.getContentText());

      for (var i in json.items) {
        Logger.log("[%s] %s %s", json.items[i].id, json.items[i].name, json.items[i].url);
      }
    }

How can I import the values that are in the Logger.log into my sheet.

You have to change the Logger.log() for appendRow() . In your case you have to set the sheet you want to insert the values:

var ss = SpreadsheetApp.getActiveSpreadsheet();  // Gets the Active Spreadsheet
var ss = SpreadsheetApp.openById("ID OF THE SPREADSHEET"); // Alternative way of getting a Spreadsheet

var sheet = ss.getSheets()[0]; // Gets the first sheet
var sheet = ss.getSheets().getSheetByName("Sheet4"); // Gets the sheet with the name Sheet4

Once you have the Spreadsheet you want, inside the for loop, you insert the values:

sheet.appendRow([json.items[i].id, json.items[i].name, json.items[i].url]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM