首页 > 解决方案 > 如何将我的值附加到谷歌电子表格 OAUTH/GAPI js

问题描述

我想创建 chrome 扩展,它使用 oauth 和 google apis(gapi) 在 google 表格中附加文本;你可以给我看代码示例吗?我在 background.js 中有这段代码


function onGAPILoad() {
  gapi.client.init({
 
    apiKey: API_KEY,
    discoveryDocs: DISCOVERY_DOCS,
  }).then(function () {
    console.log('gapi initialized')
    chrome.identity.getAuthToken({interactive: true}, function(token) {
      gapi.auth.setToken({
        'access_token': token,
      });
      gapi.client.sheets.spreadsheets.values.get({
        spreadsheetId: SPREADSHEET_ID,
        range: 'Sheet1',
      }).then(function(response) {
        console.log(response)
      

      });
    })
    

  }, function(error) {
    console.log('error', error)
  })
}


标签: javascriptgoogle-chrome-extensionoauth

解决方案


推荐阅读