firebase - 如何使用 Google Apps 脚本将数据写入 Firebase Cloud Firestore
问题描述
我正在尝试使用 Google Apps 脚本将测试数据写入我的 Firebase Cloud Firestore。运行我的脚本后writeDataToFirestore()
,我希望看到我的 GAS 和我的 firestore 中的测试数据成功执行。但是,相反,我收到以下错误。
执行失败:无效参数:密钥(第 57 行,文件“Authenticate”,项目“FirestoreApp”)
我按照此处所有文档的说明从云平台获取我的client_email
,private_key
和。project_id
function writeDataToFirestore() {
// library: 1VUSl4b1r1eoNcRWotZM3e87ygkxvXltOgyDZhixqncz9lQ3MjfT1iKFw
var email = my.client_email;
var key = my.private_key;
var projectId = my.project_id;
var firestore = FirestoreApp.getFirestore(email, key, projectId);
const data = {
"name": "test!"
};
firestore.createDocument("FirstCollection", data);
}
这是整个执行记录。
执行记录
[19-10-25 15:45:32:675 PDT] 开始执行
[19-10-25 15:45:32:719 PDT] Utilities.base64EncodeWebSafe([{"alg":"RS256","typ ":"JWT"}]) [0 秒]
[19-10-25 15:45:32:719 PDT] Utilities.base64EncodeWebSafe([{"scope":" https://www.googleapis.com/auth/数据存储","aud":" https://oauth2.googleapis.com/token ","exp":1572047132.691,"iat":1572043532.691}]) [0 秒]
[19-10-25 15:45:32 :723 PDT] Utilities.computeRsaSha256Signature([eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvZGF0YXN0b3JlIiwiYXVkIjoiaHR0cHM6Ly9vYXV0aDIuZ29vZ2xlYXBpcy5jb20vdG9rZW4iLCJleHAiOjE1NzIwNDcxMzIuNjkxLCJpYX...) [0. 003秒]
[19-10-25 15:45:32:732 PDT] 执行失败:无效参数:密钥(第 57 行,文件“Authenticate”,项目“FirestoreApp”)[0.033 秒总运行时间]
解决方案
推荐阅读
- html - 如何让 HTML 元素跨越同一个类但不被链接
- javascript - 在未填写正确表单时禁用提交 js
- reactjs - 反应快照测试中的模拟状态?
- python - Python:如何使用欧几里得算法从列表中选择心形 X、Y 点
- spring-boot - GenericJackson2JsonRedisSerializer 忽略类和属性
- javascript - 我正在使用“ng-multiselect-dropdown”,但是当我选择列表时,所选值显示在下拉列表的输入侧
- angular - 为什么 TypeScript 会给出错误消息 Property 'value' does not exist on type 'unknown'?
- sql - 如何在mysql中更新具有相同值的多行
- angular - Angular 单个可观察者,多个观察者
- python - TypeError:参数“字符串”的类型不正确(预期为 str,得到浮点数)