2017-04-06 11 views
0

새 게시물을 Firebase Realtime Database에 삽입 할 때 모든 장치에 푸시 알림을 보내기위한 Firebase 기능을 만들려고했습니다. 내 장치 토큰은 프로필 알림 끝점 아래에 있습니다. 새 게시물을 데이터베이스에 삽입하여 내 기능을 실행하려고하면 내 응답이 예상치 못한 결과를 낳습니다. https://firebase.google.com/docs/functions/https://firebase.google.com/docs/reference/admin/node/admin.database에서 문서를 읽었지만 그 이상은 얻을 수 없었습니다.Firepoint 데이터베이스 쿼리가 모든 엔드 포인트에 대해 동일한 데이터를 반환합니다.

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과를 얻을 : 여기 내 로그는 내가 기대했던 것에 가까운 아무것도. 결제 계정이 없기 때문에 이것이 가능합니까? 누군가가 나를 도울 수 있습니까? 여기 내 코드도 있습니다. jacobawenger는 의견에서 지적

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

으로, 문제는 resultDataSnapshot이라고했다, 그래서 나는 그것의 가치를 얻을 수 result.val()를 추가 할 필요가 있었다.