Start a new topic

Delete user

I'm trying to delete a user from Google App Engine using the Java SDK.



I tried the following, but it doesn't work.

Query userQuery = javaClient.query(); userQuery.equals("customer_id", 12345);



User user[] = (User[]) javaClient.user().retrieveBlocking(userQuery).execute();



user[0].deleteBlocking(true).execute();



Is there a different method to delete the user?

Good to hear it works-- sorry about that, AsyncUser is from the Android library and I always default back to that.
I couldn't find the AsyncUser class in any of the packages, however I was able to just use the regular User class and it worked correctly. Updated code below.



String appKey = ((KinveyClientRequestInitializer) getClient().getKinveyRequestInitializer()).getAppKey();

String appSecret = ((KinveyClientRequestInitializer) getClient().getKinveyRequestInitializer()).getAppSecret();



User userAPI = new User(getClient(), User.class, new KinveyAuthRequest.Builder(getClient().getRequestFactory().getTransport(),

getClient().getJsonFactory(), getClient().getBaseUrl(), appKey, appSecret, null));

userAPI.setId("my user id to delete");

try{

userAPI.deleteBlocking(true).execute();

}catch (IOException e){

e.printStackTrace();

}



Thanks.
Hey, this looks like an issue with the Java library, thank you for bringing it up.



The problem is that all user operations are meant to be performed on the logged in user, which doesn't quite make sense with the Java library where the app credentials are used to log in and not a specific User.



As a workaround, can you try the following?



String appKey = ((KinveyClientRequestInitializer) getClient().getKinveyRequestInitializer()).getAppKey();

String appSecret = ((KinveyClientRequestInitializer) getClient().getKinveyRequestInitializer()).getAppSecret();



User userAPI = new AsyncUser(getClient(), User.class, new KinveyAuthRequest.Builder(getClient().getRequestFactory().getTransport(),

getClient().getJsonFactory(), getClient().getBaseUrl(), appKey, appSecret, null));

userAPI.setId("my user id to delete");

try{

userAPI.deleteBlocking(true).execute();

}catch (IOException e){

e.printStackTrace();

}





While that looks complicated, it will just initialize a `dummy` User object (called userAPI), with app credentials, a json parser, and an http transport. After that, it overrides the default id value-- note replace "my user id to delete" with the user's _id you wish to delete.
I added the debug logging, but since the call throws an exception that's the only information I get.
Hi Edward,



I get the following NPE on the deletedBlocking(true).execute():

"NullPointerException: abstractKinveyClient must not be null"



I verified that the user[0] is not null by printing out the username right before the delete method.



I will try to enable debug logging, let me know if you've seen this exception before.



Thanks.
Hey,



That is the correct method to use, and I just did a quick test and it seems to be functional.



When you say it doesn't work, what is happening? Is the method throwing an exception or is just nothing happening?



Also, have you had a chance to look at the troubleshooting guide? If you can, enable debug logging and post the HTTP request and response from the logs. Thanks!



http://devcenter.kinvey.com/java/guides/troubleshooting
Login or Signup to post a comment