【问题标题】:Is it possible calling other API in Cloud functions using firebase?是否可以使用 firebase 在 Cloud 函数中调用其他 API?
【发布时间】:2018-06-17 07:38:15
【问题描述】:

我想在 iOS 上做一些推送警报

当用户在特定时间设置警报,并且服务器通过调用天气 API(例如 OpenweatherMap)在该时间发送天气数据。

是否可以在 Firebase 中使用云功能

【问题讨论】:

    标签: ios firebase push-notification google-cloud-functions


    【解决方案1】:

    是的,这可以通过请求模块来完成。

    查看Use firebase cloud function to send POST request to non-google server,您会在哪里找到:

    // import the module
    var request = require('request');
    
    // make the request
    request('put your external url here', function (error, response, body) {
        if (!error && response.statusCode == 200) {
            //here put what you want to do with the request
        }
    })
    

    请注意,您必须激活付费计划,因为免费计划(Spark 计划)仅允许“仅对 Google 拥有的服务的出站网络请求”

    还请注意,您必须先安装请求包,然后才能如上所示调用它。

    【讨论】:

    • 太棒了!谢谢!
    • @Renaud Tarnec 你知道如何让 JWT 令牌包含在外部请求中吗?我需要调用另一台服务器,但它需要 JWT 令牌进行身份验证(以及 JWT 中的自定义声明)
    猜你喜欢
    • 2020-01-08
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 2019-07-26
    • 2018-01-24
    • 2014-03-10
    • 2021-03-12
    • 1970-01-01
    相关资源
    最近更新 更多