简体   繁体   English

将Parse.Cloud.httpRequest与Express结合使用时出现问题,没有成功的此类方法:

[英]Problems using Parse.Cloud.httpRequest with Express, says no such method for success:

I'm hitting a facebook graph search URL, in Parse Express. 我在Parse Express中找到了一个Facebook图形搜索URL。 The call is made with a Parse.Cloud.httpRequest . 调用通过Parse.Cloud.httpRequest

I get a 500 Internal Server Error response, and when I look in the logs I see: 我收到500 Internal Server Error响应,当我查看日志时,看到:

  1. an error saying that the httpRequest has no method named success: (even though the code i'm using is based right off examples on Parse.com). 一个错误,指出httpRequest没有名为成功的方法:(即使我使用的代码是基于Parse.com上的示例)。
  2. The basic JSON data is there successfully retrieved but the error has prevented the function completing. 可以成功检索到基本JSON数据,但是该错误阻止了该函数完成。

Here's the code, all tips appreciated: 这是代码,感谢所有提示:

// 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();

I just use promises. 我只是用诺言。 This seems to work for me: 这似乎为我工作:

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);
    });

More info from parse website here 来自解析网站的更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM