0
こんにちは私はNode.js環境でFireFoxのクラウド機能を使用して特定のトピックにユーザを登録したいと考えています。このビデオに続いてhttps://www.youtube.com/watch?v=GNR9El3XWYo Firebaseの専門家Firebase内のノードへの書き込みが行われたときに、ユーザーをサブスクライブする方法を示し、here's私の完全なコード:FireFoxのクラウド機能 - トピックにユーザを登録する
//For subscriptions
exports.privateEventSubs = functions.database.ref("Events/{eventID}/guest_mod/assistants/{guestEmail}").onWrite((event) => {
let data = event.data;
let eventID = data.ref.parent.parent.parent.key;
console.log("The eventID is: " + eventID);
let guestEmail = data.ref.key;
console.log("The guestEmail is: " + guestEmail);
//Add or remove a subscription
let action = data.exists() ? "batchAdd" : "batchRemove";
console.log("The action is: " + action);
//Get the device token from each user
admin.database().ref("Users/" + guestEmail + "/chat_data/firebaseToken").once("value").then(function (snapshot) {
console.log("The user token is: " + snapshot.val());
//Send messages to users that have subscribed to that event
functions.config().firebase.credential.getAccessToken().then(function (oauthToken) {
console.log("The oauthToken is: " + oauthToken.access_token);
//Lets configure and request
request({
url: "https://iid.googleapis.com/iid/v1:" + action, //URL to hit
method: 'POST',
json: true,
headers: {
Authorization: "Bearer " + oauthToken.access_token,
access_token_auth: true,
},
body: {
to: "/Events/" + eventID,
registration_tokens: snapshot.val()
}
}, function (err, res, body) {
if (err) {
console.log(err);
} else {
console.log(res.statusCode, body);
}
});
});
});
});
私が手にエラーはこの1つである:
私は何をやっている400 { error: 'InvalidListOfTokens' }
違う?助けてください!だから、registration_tokens: [snapshot.val()]
へregistration_tokens: snapshot.val()
を変更するフォーマットでリクエストを:(あなたはregistration_tokens
キーのために単一の値を渡しているように見える。この場合
質問とエラーが更新されました! – Andrea