javascript - 在 Express 中使用 Parse.Cloud.httpRequest 时出现问题,表示没有这样的成功方法 :

标签 javascript xml json express parse-platform

我正在 Parse Express 中点击 Facebook 图形搜索 URL。该调用是通过 Parse.Cloud.httpRequest 进行的。

我收到 500 Internal Server Error 响应,当我查看日志时,我看到:

  1. 出现错误,指出 httpRequest 没有名为 success 的方法:(即使我使用的代码是基于 Parse.com 上的示例)。
  2. 已成功检索基本 JSON 数据,但错误导致函数无法完成。

这是代码,感谢所有提示:

// These two lines are required to initialize Express in Cloud Code.
 var module = require('cloud/jsonml.js');
 var Buffer = require('buffer').Buffer;
 var express = require('express');
 var app = express();

// Global app configuration section
 app.set('views', 'cloud/views');  // Specify the folder to find templates
 app.set('view engine', 'ejs');    // Set the template engine
 app.use(express.bodyParser());    // Middleware for reading request body


 app.get('/hello', function(request, response) {
    Parse.Cloud.httpRequest({
                            url: 'a-facebook-graph-url',
                            success: function(httpResponse) {
                            console.log(httpResponse.data);
                            response.success(httpResponse.data);
                            var xml = module.stringify(httpResponse.data);
                            var base64xml = xml.data.base64;
                            console.log(base64xml);
                            res.render('hello.ejs',{ message: base64xml });
                            },
                            error:function(httpResponse){
                            console.error('Error:' + httpResponse.message);
                            response.error("Failed to parse feed");
                            res.render('hello.ejs',{ message: httpResponse.message });
                            }
        });
     });

 app.listen();

最佳答案

我只使用 promise 。这似乎对我有用:

Parse.Cloud.httpRequest({
      url: 'a-facebook-graph-url'
    }).then(function(httpResponse) {
      console.log(httpResponse.text); 
      var xml = module.stringify(httpResponse.data);
      var base64xml = xml.data.base64;
      res.render('hello', 
        { 
            message: base64xml 
        });
    }, function(httpResponse) {
      console.error('Request failed with response code ' + httpResponse.status);
    });

更多信息来自解析网站here

关于javascript - 在 Express 中使用 Parse.Cloud.httpRequest 时出现问题,表示没有这样的成功方法 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29816464/

相关文章:

javascript - 如何在新的 Facebook JavaScript SDK 中请求权限?

c++ - 在 C++ (Win32) 中解析 XML 的方法

python - 为什么我收到 SyntaxError : (unicode error) 'utf-8' codec can't decode byte 0x96 in position 0: invalid start byte

php - 如何从反向地理编码 JSON 结果中获取格式化地址?

java - 如何使用java代码在 Assets 中动态创建JSON文件或在android中使用java代码更新现有的json文件

javascript - 响应式设计和点击事件

javascript - 如何覆盖 Jquery 自动完成的用户输入?

c# - 当内容之间没有空格时 GridView 中的对齐问题

C# - 在另一个类中调用/编写反序列化方法

xml - Scala - 修改 xml 中的嵌套元素