我正在 Parse Express 中点击 Facebook 图形搜索 URL。该调用是通过 Parse.Cloud.httpRequest
进行的。
我收到 500 Internal Server Error
响应,当我查看日志时,我看到:
- 出现错误,指出
httpRequest
没有名为 success 的方法:(即使我使用的代码是基于 Parse.com 上的示例)。 - 已成功检索基本 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/