Google Chat API - downloading messages in Google Apps Script to Google Sheets

69 Views Asked by At

I have Google Sheets linked with Google Chat API and Google Cloud Platform (with activated Google Chat API).

I can’t download messages from Google Chat via API. These credentials download messages in APIs Explorer documentation in Method: spaces.messages.list.

Where is bug?

Thanks for your help!

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Wiadomości");
  var url = 'https://chat.googleapis.com/v1/spaces/AAAApZWl6TI/messages?filter=thread.name%3Dspaces%2FAAAApZWl6TI%2Fthreads%2F_4hBMxTezfo';
  
  var options = {
    'method' : 'get',
    'headers': {
      'Authorization': 'Bearer ' + ScriptApp.getOAuthToken(),
      'Accept': 'application/json'
    },
    'muteHttpExceptions': true
  };

  var response = UrlFetchApp.fetch(url, options);
  var json = JSON.parse(response.getContentText());

  if (json.messages) {
    json.messages.forEach(function(message) {
      sheet.appendRow([message.name, message.text, message.createTime]);
    });
  }
}

0

There are 0 best solutions below