首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何发出functions.httpsCallable("findItems").call(["lat":userLocation?.latitude,"long":userLocation?.longitude])请求?

如何发出functions.httpsCallable("findItems").call(["lat":userLocation?.latitude,"long":userLocation?.longitude])请求?
EN

Stack Overflow用户
提问于 2020-11-05 21:53:10
回答 1查看 44关注 0票数 0

有关firebase functions.httpsCallable("findItems").call()用法的文档不足。我已经在firebase上部署了函数:

代码语言:javascript
复制
exports.findItems = functions.https.onCall((data, context) => {
// Grab the long parameter.
functions.logger.log(data.long, typeof data.long);
functions.logger.log(data.lat, typeof data.lat);
const long = parseFloat(data.long);
const lat = parseFloat(data.lat);
functions.logger.log(long, typeof long);
functions.logger.log(lat, typeof lat);
    //...
}

我在swift中使用functions.httpsCallable("findItems").call()发出请求,但日志总是显示没有正确的参数:

代码语言:javascript
复制
functions.httpsCallable("findItems").call(["lat": userLocation?.latitude, "long": userLocation?.longitude]) { (result, error) in
            if let error = error as NSError? {
                if error.domain == FunctionsErrorDomain {
                    let code = FunctionsErrorCode(rawValue: error.code)
                    let message = error.localizedDescription
                    let details = error.userInfo[FunctionsErrorDetailsKey]
                }
                // ...
                print(error)
                return
            }
            print(result?.data)
            do{
                let json =  try JSONDecoder().decode([ItemLocation].self, from:result?.data as! Data)
                print(json)
            }catch{

            }
            
            
            
//            if let text = (result?.data as? [String: Any])?

            
            //(result?.data as? [String: Any])?["text"] as? String {
            //self.resultField.text = text
        }

您可以在以下网址找到官方文档:https://firebase.google.com/docs/functions/callable

--更新

我已经通过调试尝试了所有的方法,传递的参数总是未定义的,但我遵循官方文档中的每一步。我已经做了更改并使用了onCall,但它仍然不起作用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-06 00:04:05

您混淆了HTTP函数和可调用函数。您的客户端代码试图调用一个可调用的函数,但您的函数本身被定义为HTTP函数。这根本行不通。您应该查看可调用函数的文档,并使用functions.https.onCall而不是functions.https.onRequest来定义您的函数。它们是完全不同的API。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64698634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档