首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从firebase functions- actions-on-google获取部分api数据

从firebase functions- actions-on-google获取部分api数据
EN

Stack Overflow用户
提问于 2018-01-08 14:26:25
回答 1查看 61关注 0票数 0

当我试图从托管在firebase函数上的webhook访问google操作的外部API时,我只能得到部分内容。它停止获取api提供的全部数据。例如,我尝试使用以下代码从wikipedia api获取数据

代码语言:javascript
复制
var request = require('request');//required module
//inside the function
request({ method: 'GET',url:'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&explaintext=&exsectionformat=plain&redirects=&titles=11_September'},function (error, response, body)
        {
            if (!error && response.statusCode == 200) 
            {
                console.log(body);  
            }

        });
app.ask('data obtained');

有谁能帮我解决这个问题吗。我有一个即付即用的火库帐户,允许数据出口。

EN

回答 1

Stack Overflow用户

发布于 2018-01-08 18:33:47

仅从代码片段来看,问题是您在request()回调之外回复用户。这意味着它会被立即处理,并且函数可能会在接收到整个正文之前结束。尝试这样做(我还将ask()更改为tell(),因为您在这里没有提示另一个响应,并且您不应该让麦克风保持打开状态。)

代码语言:javascript
复制
var request = require('request');//required module
//inside the function
request({ method: 'GET',url:'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&explaintext=&exsectionformat=plain&redirects=&titles=11_September'},function (error, response, body)
        {
            if (!error && response.statusCode == 200) 
            {
                console.log(body);  
                app.tell('data obtained');
            }

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

https://stackoverflow.com/questions/48145241

复制
相关文章

相似问题

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