【问题标题】:calling slack-hubot api with javascript _ result body always undefined使用 javascript 调用 slack-hubot api _ 结果正文始终未定义
【发布时间】:2015-07-19 06:32:29
【问题描述】:

但它总是返回未定义的主体。

这是我的源代码。 : 静态变量

const TOKEN = 'xoxp-7186818662-7186899793-7811139362-ccc6df';
const emojiAPIUrl = 'https://slack.com/api/emoji.list';

:用途

module.exports = function (robot) {
    robot.hear(/show emoji/igm, function(msg){
        var paramData = {'token' : TOKEN};
        var result = robot.http(emojiAPIUrl)
                        .headers({'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded'})
                        .post(paramData, function(error, res, body){
                            console.log('err >> ' + error);
                            console.log('res >> ' + stringifyObject(res));
                            console.log('body >> ' + body);
                        });
    });
};

以下是我得到的结果。

2015-07-19T06:22:27.303867+00:00 app[web.1]: err >> Error: socket hang up
2015-07-19T06:22:27.303960+00:00 app[web.1]: res >> 
2015-07-19T06:22:27.304014+00:00 app[web.1]: body >> undefined

你可以通过调用下面的url来查看结果

https://slack.com/api/emoji.list?token=xoxp-7186818662-7186899793-7811139362-ccc6df

我不明白为什么不能得到像 url 这样的 json 结果。 谢谢:D

附:如果您知道使用 javascript 的 hubot 脚本指南,请分享:D。网络上有很多示例,但大多数是咖啡脚本,很难参考:-

【问题讨论】:

  • 我建议你避免在 Stack Overflow 上发布真正的代币。

标签: javascript ajax hubot slack-api


【解决方案1】:

URL https://slack.com/api/emoji.list?token=xoxp-7186818662-7186899793-7811139362-ccc6df 中的不是 POST,而是 GET,所以你应该这样做:

robot.http("https://slack.com/api/emoji.list?token=xoxp-7186818662-7186899793-7811139362-ccc6df")
  .get()(function(err, res, body) {
     console.log(body);
  }
);

【讨论】:

    猜你喜欢
    • 2012-02-27
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 2022-01-21
    • 2017-01-21
    • 1970-01-01
    • 2023-03-19
    • 2015-04-26
    相关资源
    最近更新 更多