Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase onCall云函数请求返回“;无效的“U参数”;_Javascript_Node.js_Firebase_Google Cloud Functions - Fatal编程技术网

Javascript Firebase onCall云函数请求返回“;无效的“U参数”;

Javascript Firebase onCall云函数请求返回“;无效的“U参数”;,javascript,node.js,firebase,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Functions,尝试访问my cloud功能时出错: {“错误”:{“消息”:“错误请求”,“状态”:“无效参数”} 如果调用了客户机触发器,但请求错误 格式,例如不是JSON、具有无效字段或缺少 数据字段中,请求被拒绝,错误请求为400,错误请求为 无效参数的错误代码 Firebase文档: 函数目录中的index.js const functions = require('firebase-functions'); var admin = require("firebase-admin"

尝试访问my cloud功能时出错:

{“错误”:{“消息”:“错误请求”,“状态”:“无效参数”}

如果调用了客户机触发器,但请求错误 格式,例如不是JSON、具有无效字段或缺少 数据字段中,请求被拒绝,错误请求为400,错误请求为 无效参数的错误代码

Firebase文档:

函数目录中的index.js

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

var admin = require("firebase-admin");
var serviceAccount = require("./fir-email-b4c1f-firebase-adminsdk-xj7ug-d01651ffc9");


admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://fir-email-b4c1f.firebaseio.com"
});



    exports.getUserByEmail = functions.https.onCall((data, context) => {

const email = data.email;

return admin.auth().getUserByEmail(email)
    .then(userRecord => {
    console.log('Successfully fetched user data:', userRecord.toJSON());
    const userData = userRecord.toJSON();
    return { userData: userData };
})
    function retrieveUserData() {

    var emailString = "test@gmail.com";
    var userEmail = firebase.functions().httpsCallable('getUserByEmail');

    userEmail({email: emailString}).then(function(result) {
        // Read result of the Cloud Function.
        var emailResult = result.data.text;
        console.log('Successfully fetched user data:', emailResult.toJSON());


    })

}
}))

authentication.js在项目主目录中调用函数

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

var admin = require("firebase-admin");
var serviceAccount = require("./fir-email-b4c1f-firebase-adminsdk-xj7ug-d01651ffc9");


admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://fir-email-b4c1f.firebaseio.com"
});



    exports.getUserByEmail = functions.https.onCall((data, context) => {

const email = data.email;

return admin.auth().getUserByEmail(email)
    .then(userRecord => {
    console.log('Successfully fetched user data:', userRecord.toJSON());
    const userData = userRecord.toJSON();
    return { userData: userData };
})
    function retrieveUserData() {

    var emailString = "test@gmail.com";
    var userEmail = firebase.functions().httpsCallable('getUserByEmail');

    userEmail({email: emailString}).then(function(result) {
        // Read result of the Cloud Function.
        var emailResult = result.data.text;
        console.log('Successfully fetched user data:', emailResult.toJSON());


    })

}

没有完全理解错误。我想我遗漏了一个基于文档的论点。有人能给我指点方向吗。

是的,看来你确实错过了一场辩论。
getUserByEmail()
函数的第一个参数(
data
)应该是一个包含以下属性的对象:
email
,来自此行:
const from=data.sender。但是当调用它时,您只传递了一个具有
text
属性的对象。这意味着,当您的云功能运行时,data.email是未定义的

可能,您的意思是这样调用函数:

userEmail({email:emailString})。然后(函数(结果){
//读取云函数的结果。
}
更新:关于第二个问题: 云函数返回的对象只有一个单独的属性:
userData
,因此,如果要在输出中记录返回的值,需要替换

var emailResult=result.data.text;
log('成功获取用户数据:',emailResult.toJSON());
为此:

var emailResult=result.data.userData;
log('已成功获取用户数据:',emailResult);

所有额外字段:
result.data.text
在返回的对象上不存在。并且您已经在云函数中将firebase响应转换为JSON。您不能在客户端上再次执行此操作

请查看更新的代码。我现在得到一个“Uncaught”(承诺中)TypeError:无法读取undefined的属性'toJSON'“如果userRecord未定义,您应该确认您提供的用户电子邮件确实存在于数据库中用户电子邮件在数据库中已确认?如在集合中?非常感谢您的帮助。非常感谢您。