I am trying to update a record in kinvey collection but it keep saying insufficient credentials i found a similar question on the forum that said i have to setGloballyWriteable to the acl of my model i have done that but still have the error here is my code
public void loadMenuHelper(){
menu_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Order order = my_orders[position];
order.getAcl().setGloballyWriteable(true);
order.getAcl().setGloballyReadable(true);
int requests = order.getRequests();
////////////have the handler
AlertDialog.Builder alert = new AlertDialog.Builder(
new ContextThemeWrapper(ImageTargets.this, R.style.AlertDialogCustom));
LinearLayout layout = new LinearLayout(ImageTargets.this);
layout.setOrientation(LinearLayout.VERTICAL);
alert.setTitle("There are " + requests + "Before you");
alert.setView(layout);
alert.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
///////////////
order.getAcl().setGloballyWriteable(true);
order.getAcl().setGloballyReadable(true);
order.setRequests(order.getRequests() + 1);
AsyncAppData<Order> myevents = mKinveyClient.appData("Order", Order.class);
myevents.save(order, new KinveyClientCallback<Order>() {
@Override
public void onFailure(Throwable e) {
Log.i("TAG", "failed to save event data" + e.getMessage());
Log.i("TAG", sharedpreferences.getString("owner_name", ""));
}
@Override
public void onSuccess(Order r) {
Log.d("TAG", "saved data for entity " + r.getName());
Toast.makeText(getApplicationContext(), "Your Order was Created Sucessfully", Toast.LENGTH_SHORT).show();
}
});
}
////////////
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
}
});
alert.show();
////////////////
}
});
///////////////
}
Considering that you have a user properly logged in, this seems to be related to collection permissions.
Your collection is in shared mode, that's why you are able to read the order object created by somebody else. But, because only creator can modify the object, you are getting "insufficient credentials" error.
You have two options here. The first option is to change collection permissions to public so that anybody can edit any order object. You can do that in Kinvey web console by going to settings tab in the data browser for the Order collection. After this, you won't need to use setGloballyWriteable/setGloballyReadable.
Other option (better suitable according to me) is to create another collection for requests for specific orders. In this new collection, you will be able to store a reference of the order object as well as store user information about the user who requested it.
You can find necessary documentation related to collection permissions here - http://devcenter.kinvey.com/android/guides/security