I use parse to handle push notification. Because I already have my own database, I use parse to store installation data only.(Not using ParseUser to login and logout in the app) When I logout my app, I would like to delete 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!
I think you are trying to make a request with a user who doesn't have enough authorizathion to do it. Maybe, you are doing this request when the session is already destroyed(for logout),instead of doing it before destroying it.
You have to delete it from Cloud Code using master key.
In the 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 wish to also delete the cached Installation on your device, do the following:
Create a package named com.parse
Crate a class, like for example MyParseTools.
Make a static method liks so:
public static void clearParseInstallation() {
ParseInstallation.getCurrentInstallationController().clearFromDisk();
ParseInstallation.getCurrentInstallationController().clearFromMemory();}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With