简体   繁体   中英

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

I'm hitting a facebook graph search URL, in Parse Express. The call is made with a Parse.Cloud.httpRequest .

I get a 500 Internal Server Error response, and when I look in the logs I see:

  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).
  2. The basic JSON data is there successfully retrieved but the error has prevented the function completing.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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