Android 解析云函数失败

Android 解析云函数失败,android,parse-platform,Android,Parse Platform,我正试图通过云代码删除一个文件。 但是这个脚本失败了: Parse.Cloud.define("deleteFile1", function(request, response) { Parse.Cloud.httpRequest({ method: 'DELETE', url: 'https://api.parse.com/1/files/****.png', headers: { "X-Parse-Application-

我正试图通过云代码删除一个文件。 但是这个脚本失败了:

    Parse.Cloud.define("deleteFile1", function(request, response) {
  Parse.Cloud.httpRequest({
       method: 'DELETE',
       url: 'https://api.parse.com/1/files/****.png',
       headers: {
        "X-Parse-Application-Id": "*******",
        "X-Parse-REST-API-Key" : "*******"
       },
       success: function(httpResponse) {
            console.log('Delete succeeded  ' + httpResponse.text);
        response.success();
       },
       error: function(httpResponse) {
                response.error("failed");
       }
       });
});
出现错误141,脚本失败

我这样称呼它:

Map<String, String> map = new HashMap<String, String>();
    ParseCloud.callFunctionInBackground("deleteFile1", map, new FunctionCallback<Object>() {
        @Override
        public void done(Object object, ParseException e) {
            if(e == null){

            }else{
                System.out.println(e.getCode());
                utils.toast_error("Couldn't delete image.. try again");
            }

        }
    });
Map Map=newhashmap();
ParseCloud.callFunctionInBackground(“deleteFile1”,映射,新函数回调(){
@凌驾
公共void已完成(对象,parsee异常){
如果(e==null){
}否则{
System.out.println(e.getCode());
utils.toast_错误(“无法删除图像..重试”);
}
}
});

我检查了我的钥匙,它们是正确的。因此,脚本本身在某种程度上肯定是错误的。我想可能是网址。是否假定/files是图像文件绑定到的解析文件?我尝试将“请求”和“响应”更改为httpResponse等,但没有任何区别。

更新的代码现在至少运行正常,并且您能够捕获错误

通过修改错误处理程序以返回
httpResponse.text
,可以返回实际消息:

    error: function(httpResponse) {
        response.error("failed " + httpResponse.text);
    }
最初,我使用了错误的
X-Parse-REST-API-Key
,得到了以下错误:

{
    "code": 141,
    "error": "failed {\"error\":\"unauthorized\"}\n"
}
确保使用MASTER键:
X-Parse-MASTER-key
。这修复了我这边的代码,运行良好


原始代码失败,因为您没有在响应完成时调用
success()

下面是调用
/deleteFile1时接收的JSON响应;这表明这就是问题所在:

{
    code: 141
    error: "success/error was not called"
}
如果查看,您将看到每个方法都使用
response
(或者在代码中使用
httpResponse
)参数,并在完成后调用
response.success()

始终阅读Parse发送回您的响应-这可能有助于理解错误


找到了相关的帖子,并给出了相同的答案:


请查看Parse.com上的“我的编辑,我的日志信息”选项卡,现在从脚本中记录“失败”。呵呵,没问题!是的,我也看到了,主要的区别是什么?基本上只是一个更大、更好、功能齐全的云代码版本。(同样,迈凯轮P1就像一辆更新的、功能齐全的T型福特……)