Tag: google cloud functions

从本地运行的云function调用“subscribeToTopic”

我不断收到权限错误… “尝试向FCM服务器进行身份validation时发生错误,请确保用于validation此SDK的凭据具有适当的权限,有关安装说明,请参阅https://firebase.google.com/docs/admin/setup 。 …当我在本地运行调用subscribeToTopic和unsubscribeToTopic的云function。 当我将我的函数部署到firebase时,这个问题不会发生。 我正在使用firebase-admin并在我的云端function中设置firebase … const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); authentication问题只发生在调用subscribeToTopic和unsubscribeToTopic 。 从云端函数写入数据库可以正常工作。 我可以通过调用admin.initializeApp通过admin.initializeApp控制台创build的生成的服务帐户json文件)来解决此问题。 任何想法,为什么发生这种情况?

Firebase – NodeJS:用于Google API的OAuth2域范围委派

目标: 此Firebase云端function应使用Cloud API与域范围委派,以便任何用户在Firebase数据库更改时更新一些 G Suitepipe理控制台用户信息。 题: 我应该使用哪个包的方法来获得应用程序的广泛代理权。 firebase : firebase.auth.GoogleAuthProvider() googleapis : google.auth.OAuth2 google-auth-library : new GoogleAuth() 细节: 关于Google Identity Platform ,我并没有把这个问题连接起来,而我却陷入了这一步 。 firebase托pipe的nodejs应用如何将Google API请求的Web和访问令牌放在一起? Firebase项目使用Google云端平台项目 我有… 通过GCP-Console中的API /凭证添加到项目中的service account actor 选中启用G Suite域范围委派框 存储private_key.JSON。 授权API客户端(位于G Suitepipe理控制台中)和服务帐户客户端ID 我应该使用… Firebase :可能会查看Google OAuth2设置的白名单区域 ,和/或使用我从firebase获得的services.json 。 Google API通过googleapis :尽pipe我使用firebase.auth.GoogleAuthProvider()来validation用户,也许可以使用google.auth.OAuth2从GCP获取域范围的委派(如应用程序或计算引擎) Google Auth通过google-auth-library :同样,即使我使用firebase.auth.GoogleAuthProvider()来validation用户,也许使用new GoogleAuth()从GCP获取域范围的委托(如应用程序或计算引擎) 更新 我学过: Google的npm包googleapis不适用于客户端(浏览器)。 我现在正尝试在Firebase云端函数中使用它

使用Google API的Firebase – 需要帐单和/或身份validation

目标 使用免费的Firebase Spark计划 ,在Firebase云端function中使用googleapis 。 上下文 我已经将以下云端function代码部署到了我的Firebase项目中。 helloWorld端点按预期工作。 urlShortener端点返回两个错误: Error: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup… 和 Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions 题 如果我发送一个validation的请求,这是否certificate了这两个错误? 或者,googleapis以某种方式被视为External network并且必须解决这两个错误,例如,打开结算以使用googleapis? 码 const functions = require('firebase-functions'); const admin = require('firebase-admin'); […]

NodeJS示例 – Firebase云function – 实例化Admin SDK目录服务对象

目标 在Firebase云端函数中使用googleapis获取我的G Suite域中所有用户的列表。 题 如何实例化一个Admin SDK目录服务对象 。 我没有看到一个NodeJS的例子,我不清楚如何设置和使用googleapis的请求。 上下文 此代码从Firebase云端函数运行,似乎可以进行身份​​validation。 现在,我如何在//TODO中的以下代码中设置服务对象: // Firebase Admin SDK const functions = require('firebase-functions') const admin = require('firebase-admin') admin.initializeApp(functions.config().firebase) // Google APIs const googleapis = require('googleapis') const drive = googleapis.drive('v3') const gsuiteAdmin = googleapis.admin('directory_v1') // Service Account Key – JSON let privatekey = require("./privatekey.json") let jwtClient = new googleapis.auth.JWT( privatekey.client_email, […]

更新检索的Firestore文档?

我磕磕绊绊地find一个我觉得很傻的问题,但似乎无法解决: 我不能直接更新从Firestore检索的文档。 例如,当我尝试在onWrite触发器中将以下代码部署到其他节点时: admin.firestore().collection("user-data").doc('someUserId').get().then(doc => { const profile = doc.data() if (profile.foo != 'bar') { return 0 } return doc.update({ objectToUpdate: { fieldToUpdate: 'Foo is not bar!'} }) 我得到的错误, doc.update is not a function 我也试过doc.ref.update和doc.data.ref.update ,但没有骰子。 我可以用admin.firestore().collection("user-data').doc('someUserId').update({…})来达到我想要的admin.firestore().collection("user-data').doc('someUserId').update({…}) ,但是感觉太笨重了… 我在这里错过了什么?

Firebase函数HTTP触发器 – 错误:无法处理请求 – Firebase未定义

提前道歉,如果我的语法不正确,因为我是Firebase的新手(和node.js)。 使用HTTP触发器,我试图从我的实时数据库中将“奖”数据作为对象。 但是,基于我的设置,当我执行从firebase deploy接收到的URL时,我收到以下错误。 错误:无法处理请求 我确实将firebase更改为admin ,但这并不能解决问题。 另外我还以为.catch()方法至less会让我理解问题是什么,而不是告诉我“错误”。 我希望最终的结果是: {"create_your_own":"false","first_time":"true","five_in_a_row":"true", "share_with_friend": "false"} 任何帮助破译我的问题,不胜感激。 function日志 实时数据库 fir-db-test-mike | |__awards | | | |__user01 | | | | | |__create_your_own: false | | |__first_time: true | | |__five_in_a_row: true | | |__share_with_friend: false | | | | | |__user02 | | | |__create_your_own: false | |__first_time: false […]

Firebase:使用云端function删除Cloud Starage中的文件

我尝试使用Cloud Functions从删除条目中的Cloud Storage删除与Realtime Database某些特定条目相关的所有文件。 我的function看起来像休闲: exports.onDeleteRequest = functions.database.ref('/requests/{requestid}/').onDelete(event => { const storage = functions.config().firebase.storageBucket; const userId = event.data.previous.child('uid').val(); const requestId = event.params.requestid; const path = storage + '/photos/' + userId + '/' + requestId; console.log('path: ', path); return gcs.bucket(path).delete().then(function() { console.log("Files removed"); }).catch(function(error) { console.error("Failed removing files", error); }); }); 但是,我继续在日志中出现以下错误: Failed removing files { […]

Firebase云functionhttp触发响应函数循环

我写了一些代码发送一个通知给我的所有注册到一个事件的用户,我使用http触发器,将在事件启动时被调用,我不能发送通知到设备组,因为事件可能不同,即使开始时间是一样的。 我的firebase节点看起来像这样: registration |– userid1 | |– registration1 | | |– FirebaseToken | | |– EventName | |– registration2 | |– FirebaseToken | |– EventName |– userid2 这是我的脚本: exports.sendNotification = functions.https.onRequest((request, result) => { admin.database().ref('/registration').once('value').then(snapshot => { snapshot.forEach(childSnapshot => { let list = childSnapshot.val() for (let key in list) { let p = list[key]; let […]

将firebase函数转换为JavaScript的Typescript

我已经开始深入研究Firebase的云function,但是经过这么长时间,成为一名Android开发人员转而使用javascript已经非常艰难。 我已经使用firebase命令行工具(例如firebase login / init / deploy)configuration了一个新项目。 而且还需要npm和所有的依赖。 我正在使用Webstorm开发,并决定尝试按照YouTube上的video使用Typescript。 [ https://www.youtube.com/watch?v=GNR9El3XWYo&t=1106s] [1 ] 我已经设法得到我的Typescript编译,但是当转译为JavaScript时,它不能正确编译。 任何人都可以帮我解决这个问题吗? 下面的TS脚本 import * as functions from 'firebase-functions' import * as request from 'request-promise' export let addPlayerRequestNotification = functions.database .ref('notifications/{id}/notification') .onWrite(async event => { let notificaion = event.data.val(); let oauthToken = await functions.config().firebase.credential.getAccessToken(); await request ({ url: 'https://fcm.googleapis.com/fcm/send', method: 'POST', headers: […]

Firebase Init第二次只创build2个文件

所以我打算使用云function,因此我在一个文件夹中使用了firebase init ,它的工作原理是(创build了node_module,也创build了index.js) 问题出在第二个firebase init之上。 初始化只产生2个文件,即.firebaserc和.firebaserc ,没有任何错误。 我应该怎么做,以创buildindex.js和其他东西,如初始化后的node_modules文件夹? PS。 我是npm-nodejs-javascript世界中的新人,所以我不熟悉node或npm是如何工作的。 PSS。 我已经确定我的firebase-tools版本是最新的(3.9.2)