javascript - Problems using Parse.Cloud.httpRequest with Express, says no such method for success: -
i'm hitting facebook graph search url, in parse express. call made parse.cloud.httprequest
.
i 500 internal server error
response, , when in logs see:
- an error saying
httprequest
has no method named success: (even though code i'm using based right off examples on parse.com). - the basic json data there retrieved error has prevented function completing.
here's code, tips appreciated:
// these 2 lines required 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 folder find templates app.set('view engine', 'ejs'); // set template engine app.use(express.bodyparser()); // middleware 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 parse feed"); res.render('hello.ejs',{ message: httpresponse.message }); } }); }); app.listen();
i use promises. seems work 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 response code ' + httpresponse.status); });
more info parse website here