0

我正在开发一个插件,旨在使市场上的销售与 Google 表格保持同步。有一个第一次同步,将去年的订单写入工作表,这发生在附加执行中,一切都很好。

现在,当有新的销售时,我会在云功能中收到通知,我想将该信息添加到已授予插件权限的电子表格中,但我不知道如何验证请求。我已经尝试使用编辑服务帐户,并为主应用程序引擎帐户创建了一个密钥,但没有任何效果。

一切都是同一个谷歌项目的一部分,用户将是安装插件并允许访问它的任何人,我们将非常感谢一些帮助或指导。

范围插件具有权限:

"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.container.ui"

示例用法:

import { google } from 'googleapis';
import serviceAccount from '../service-account.json';

const sheets = google.sheets('v4');

const jwtClient = new google.auth.JWT({
  email: serviceAccount.client_email,
  key: serviceAccount.private_key,
  scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});

async function searchMetadata(spreadsheetId, params = {}) {
  await jwtClient.authorize();
  const response = await sheets.spreadsheets.developerMetadata.search({
    auth: jwtClient,
    spreadsheetId,
    requestBody: {
      dataFilters: [
        {
          developerMetadataLookup: params
        }
      ]
    }
  })
  return response.data;
}

谢谢!

4

0 回答 0