Reputation: 1226
I am using parse.com in my android application.when i visit other user's profile , i am able to follow that user but when i follow him value in following column of current logged in user's object is updated, but at the same time the user's value whom i followed is not updated It Gives:
06-27 05:11:44.521: E/AndroidRuntime(2459): java.lang.IllegalArgumentException: Cannot save a ParseUser that is not authenticated.
Here is my android code package com.example.wavie.parseQueryRunner;
import android.content.Context;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
public class FollowUserClass {
private String id;
private Context context;
public FollowUserClass(String id, Context context) {
this.id = id;
this.context = context;
}
public void follow() {
ParseUser currentUser=ParseUser.getCurrentUser();
currentUser.addUnique("following", id);
try {
currentUser.save();
ParseQuery<ParseObject> query=new ParseQuery<ParseObject>("_User");
query.getInBackground(id, new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
// TODO Auto-generated method stub
if(e==null && object!=null){
object.addUnique("followers", ParseUser.getCurrentUser().getObjectId());
try {
object.save();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
in the code section constructor takes the object id of the user whom i want to follow.first it updates current logged in user adds taken id in following field(array).
then i tried to make update in other user's object by adding line
object.addUnique("followers",
ParseUser.getCurrentUser().getObjectId());
but when i save it gives parse user should be authenticated before ssaving
Upvotes: 3
Views: 895
Reputation: 1226
i found the answer the next day i asked this question.that time the single way to do this is by deploying cloud code. actually the user i wanted to update was other user so it is not possible to update someone's else information in the database.parse provides a solution to do this in android(possible in js) by deploying a cloud code on the server. parse gives a command line tool to do this for linux run following command to install curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
after successfull installation a folder named parse will be created in home/etc/. now type command parse $configure accountkey -d on terminal ,it will ask for your parse credentials. now type parse command on terminal to select one of your existing application. now you open main.js file in home/etc/parse edit. switch to terminal deploy code by using $parse deploy command. now you are good to go cloud code has been deployed
Upvotes: 2
Reputation: 578
The error mentions the issue here. The user is not authenticated to perform the operation. This happens when a user updating a a row in parse is not the one who has created the respective row.
So probably you should give write access to the user who is updating the entries.
Upvotes: 0