在Parse上启动并运行第三方Cloud Code模块时遇到一些麻烦。
我正在跟随Parse.com的“与第三方服务集成”指南,似乎遇到了困境。
这是我的main.js:
var echonest = require('cloud/echonest');
echonest.initialize('MyAPIKey');
// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:
Parse.Cloud.define('hello', function(request, response) {
response.success('Hello world!');
});
Parse.Cloud.define("create", function(request, response) {
echonest.create(
{
type: "song",
name: request.params.name
}
).then(function(httpResponse) {
console.log(httpResponse);
response.success(httpResponse);
}, function(httpResponse) {
console.error(httpResponse);
response.error('create failed');
});
});
与echonest.js对话:
(function() {
var url = 'http://developer.echonest.com/api/v4/';
var key = '';
module.exports = {
initialize: function(apiKey) {
key = apiKey;
return this;
},
create: function(params, options) {
requestBody = params;
requestBody.api_key = key;
return Parse.Cloud.httpRequest({
method: 'POST',
url: url + 'tasteprofile/create',
body: requestBody,
}).then(function(httpResponse) {
if (options && options.success) {
options.success(httpResponse);
} else {
console.error('(success) options not found');
console.error(httpResponse);
}
}, function(httpResponse) {
if (options && options.error) {
options.error(httpResponse);
} else {
console.error('(error) options not found');
console.error(httpResponse);
}
});
}
}
}());
我从echonest API获得成功消息,但由于未定义选项和/或options.success,它们在echonest.js中失败。