2017-04-06 7 views
0

新しい投稿がFirebase Realtime Databaseに挿入されたときに、すべてのデバイスにプッシュ通知を送信するFirebase機能を作成しようとしました。私のデバイストークンは、プロファイル通知エンドポイントの下にあります。新しい投稿をデータベースに挿入して機能を実行しようとすると、私の応答は予期せぬものとなります。私はhttps://firebase.google.com/docs/functions/https://firebase.google.com/docs/reference/admin/node/admin.databaseからドキュメントを読んでいましたが、それ以上は得られませんでした。ここに私のログは、次のとおりです。すべてのエンドポイントの同じデータを返すFirebaseデータベースクエリ

5:23:47.451 PM \t debug sendNewPostNotification 
 
    Function execution took 1145 ms, finished with status: 'ok' 
 
\t 
 
5:23:47.447 PM info sendNewPostNotification 
 
    p:0: from server: {"r":4,"b":{"s":"ok","d":""}} 
 
\t 
 
5:23:47.446 PM info sendNewPostNotification 
 
    p:0: from server: {"r":3,"b":{"s":"ok","d":{}}} 
 
\t 
 
5:23:47.444 PM info sendNewPostNotification 
 
    Result: T { A: P { k: Sb { Ka: [Function: vb], ba: [Object] }, aa: P { k: [Object], aa: null, wb: [Object], Bb: '' }, wb: Zc { ld: [Object], ac: [Object] }, Bb: null }, V: R { u: Gd { app: [Object], L: [Object], Ua: [Object], Sc: null, ca: [Object], td: 1, Qa: [Object], va: [Object], qg: [Object], jc: [Object], ee: [Object], md: [Object], ia: [Object], Xa: [Object], cd: 1, fe: null, K: [Object] }, path: J { o: [Object], Y: 0 }, m: Df { xa: false, ka: false, Ib: false, na: false, Pb: false, oa: 0, kb: '', bc: null, xb: '', Zb: null, vb: '', g: Tc {} }, Kc: false, then: undefined, catch: undefined }, g: Tc {} } 
 
\t 
 
5:23:47.439 PM info sendNewPostNotification 
 
    p:0: {"r":4,"a":"n","b":{"p":"/profile-notifications"}} 
 
\t 
 
5:23:47.439 PM info sendNewPostNotification 
 
    p:0: Unlisten on /profile-notifications for default 
 
\t 
 
5:23:47.438 PM info sendNewPostNotification 
 
    p:0: Unlisten called for /profile-notifications default 
 
\t 
 
5:23:47.437 PM info sendNewPostNotification 
 
    event: /profile-notifications:value:{"[email protected]*com":{"deviceToken2":true},"[email protected]*com":{"deviceToken1":true}} 
 
\t 
 
5:23:47.430 PM info sendNewPostNotification 
 
    p:0: handleServerMessage d {"p":"profile-notifications","d":{"[email protected]*com":{"deviceToken2":true},"[email protected]*com":{"deviceToken1":true}}} 
 
\t 
 
5:23:47.429 PM info sendNewPostNotification 
 
    p:0: from server: {"r":2,"b":{"s":"ok","d":{"auth":null,"expires":1491492227}}} 
 
\t 
 
5:23:47.429 PM info sendNewPostNotification 
 
    c:0:0: Primary connection is healthy. 
 
\t 
 
5:23:47.290 PM info sendNewPostNotification 
 
    p:0: from server: {"r":1,"b":{"s":"ok","d":""}} 
 
\t 
 
5:23:47.289 PM info sendNewPostNotification 
 
    p:0: {"r":3,"a":"q","b":{"p":"/profile-notifications","h":""}} 
 
\t 
 
5:23:47.289 PM info sendNewPostNotification 
 
    p:0: Listen on /profile-notifications for default 
 
\t 
 
5:23:47.288 PM info sendNewPostNotification 
 
    p:0: {"r":2,"a":"gauth","b":{"cred":"ya29.El0lBHwnjCRAbk5q-vLmvHyYlxEv7zKP03kvxA7ktrRQgHpDAhDxM0bkUwfHUNaAJUxK4n7MsS1tTqXBF35NojUCPeMB5CJAhxuI8iTvXEWLvQQW-rbjUwKCIXF9oCQ"}} 
 
\t 
 
5:23:47.287 PM info sendNewPostNotification 
 
    p:0: {"r":1,"a":"s","b":{"c":{"sdk.admin_node.4-2-0":1}}} 
 
\t 
 
5:23:47.287 PM info sendNewPostNotification 
 
    p:0: reportStats {"c":{"sdk.admin_node.4-2-0":1}} 
 
\t 
 
5:23:47.285 PM info sendNewPostNotification 
 
    p:0: connection ready 
 
\t 
 
5:23:47.285 PM info sendNewPostNotification 
 
    c:0:0: Realtime connection established. 
 
\t 
 
5:23:47.283 PM info sendNewPostNotification 
 
    c:0:0:1 Websocket connected. 
 
\t 
 
5:23:47.262 PM info sendNewPostNotification 
 
    c:0:0:1 Websocket connecting to wss://s-usc1c-nss-135.firebaseio.com/.ws?v=5&ns=rally-zone 
 
\t 
 
5:23:47.262 PM info sendNewPostNotification 
 
    c:0:0:0 Websocket connection was disconnected. 
 
\t 
 
5:23:47.259 PM info sendNewPostNotification 
 
    c:0:0:0 WebSocket is being closed 
 
\t 
 
5:23:47.259 PM info sendNewPostNotification 
 
    c:0:0: Shutting down all connections 
 
\t 
 
5:23:47.259 PM info sendNewPostNotification 
 
    c:0:0: Reset packet received. New host: s-usc1c-nss-135.firebaseio.com 
 
\t 
 
5:23:47.254 PM info sendNewPostNotification 
 
    c:0:0:0 Websocket connected. 
 
\t 
 
5:23:47.167 PM info sendNewPostNotification 
 
    c:0:0:0 Websocket connecting to wss://rally-zone.firebaseio.com/.ws?v=5 
 
\t 
 
5:23:47.165 PM info sendNewPostNotification 
 
    c:0:0: Connection created 
 
\t 
 
5:23:47.164 PM info sendNewPostNotification 
 
    getToken() completed. Creating connection. 
 
\t 
 
5:23:47.162 PM info sendNewPostNotification 
 
    p:0: Auth token refreshed 
 
\t 
 
5:23:47.101 PM info sendNewPostNotification 
 
    p:0: Making a connection attempt 
 
\t 
 
5:23:47.099 PM info sendNewPostNotification 
 
    p:0: Listen called for /profile-notifications default 
 
\t 
 
5:23:47.084 PM info sendNewPostNotification 
 
    p:0: Browser went online. 
 
\t 
 
5:23:46.307 PM debug sendNewPostNotification 
 
    Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions 
 
\t 
 
5:23:46.307 PM debug sendNewPostNotification 
 
    Function execution started

だから私は見ることができるものから、データベースからの応答は、私が期待するものであるが、私は私の結果をログに記録しようとすると、私は長い間、JSONを取得します私が期待していたものに近いものはありません。請求アカウントを持っていないためにこれができますか?誰か助けてくれますか?ここに私のコードもあります。

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 

admin.initializeApp(functions.config().firebase); 

exports.sendNewPostNotification = functions.database.ref('/posts/{postId}').onWrite(event => { 
    const postId = event.params.postId; 

    admin.database.enableLogging(true); 
    return admin.database().ref("profile-notifications").once('value').then(result => { 
    if (result) { 
     console.log('Result: ', result); // "Stuff worked!" 
    } 
    }, err => { 
    console.log('Error: ', err); // Error: "It broke" 
    }); 
}); 
+0

'results'は、[DataSnapshot'](https://firebase.google.com/docs/reference/admin/node/admin.database.DataSnapshot)のオブジェクトとログをまとめたものですコード。代わりに['result.val()'](https://firebase.google.com/docs/reference/admin/node/admin.database.DataSnapshot#val)を記録して、実際の値を取得してください。 – jwngr

+0

ありがとう、これは私を助けた! –

答えて

0

jacobawengerコメントで指摘したように、問題はresultDataSnapshotだったので、私はそれの値を取得するためにresult.val()を追加するために必要なことでした。

関連する問題