Android cannot remove parsing installation

I use parsing to handle push notifications. Since I already have my own database, I use parsing to store only the installation data. (Without using ParseUser to log in and out in the application) When I exit my application, I would like to remove my installation.

ParseInstallation installation = ParseInstallation.getCurrentInstallation(); installation.deleteInBackground(new DeleteCallback() { @Override public void done(ParseException ex) { Log.d(TAG, "ParseInstallation deleteInBackground done"); if (ex != null) { Log.e(TAG, "ParseInstallation deleteInBackground", ex); } } }); 

Then I got the following error:

 com.parse.ParseRequest$ParseRequestException: forbidden at com.parse.ParseRequest.newPermanentException(ParseRequest.java:391) at com.parse.ParseRESTCommand.onResponse(ParseRESTCommand.java:197) at com.parse.ParseRequest$3.then(ParseRequest.java:258) at com.parse.ParseRequest$3.then(ParseRequest.java:254) at bolts.Task$14.run(Task.java:796) at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105) at bolts.Task.completeAfterTask(Task.java:787) at bolts.Task.continueWithTask(Task.java:599) at bolts.Task.continueWithTask(Task.java:610) at bolts.Task$12.then(Task.java:702) at bolts.Task$12.then(Task.java:690) at bolts.Task$14.run(Task.java:796) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:841) 

Thanks!

+5
source share
2 answers

I think you are trying to make a request with a user who does not have sufficient authorization to do this. Perhaps you make this request when the session is already destroyed (to log out), instead of doing this before destroying it.

+1
source

You must remove it from the cloud code using the master key.

In android client:

  //clear the installation backend HashMap<String, String> params = new HashMap<>(); String idToken = ParseInstallation.getCurrentInstallation().getInstallationId(); params.put("installationId", idToken); ParseCloud.callFunctionInBackground("removeInstallation", params, new FunctionCallback<String>() { @Override public void done(String response, ParseException e) { if (e == null) { //clear the local chache ParseEasyAccess.clearParse(); } else { e.printStackTrace(); } } }); 

And then in the Cloud Code:

  Parse.Cloud.define("removeInstallation", function(request, response) { Parse.Cloud.useMasterKey(); var installationId = request.params.installationId; var query = new Parse.Query(Parse.Installation); query.equalTo("installationId", installationId); query.find(function(installations) { installations[0].destroy().then( function() { response.success("Destroyed"); }, function() { response.error("Failed"); }); }); }); 

And if you want to also remove the cached installation on your device, follow these steps:

  • Create a package named com.parse

  • Create a class, for example, MyParseTools.

  • Make a static method like this:

     public static void clearParseInstallation() { ParseInstallation.getCurrentInstallationController().clearFromDisk(); ParseInstallation.getCurrentInstallationController().clearFromMemory();} 
+1
source

All Articles