When attempting to access a Facebook graph search URL using Parse Express, I encounter an issue. The request is made using Parse.Cloud.httpRequest
.
Instead of a successful response, I receive a 500 Internal Server Error
. Upon inspecting the logs, I find the following:
- An error indicating that the
httpRequest
method lacks a function named success, despite my code being based on examples from Parse.com. - The essential JSON data is retrieved, but due to the error, the function fails to complete.
Here is the code snippet in question. Any suggestions or advice are welcome:
// These two lines are necessary for initializing 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 where templates are located
app.set('view engine', 'ejs'); // Set the template engine
app.use(express.bodyParser()); // Middleware for reading the 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();