Skip to content Skip to sidebar Skip to footer

How To Store Some Particular Data For Some Particular Parse User In Android

In my application i want to store some specific data for a particular parse user and I want to fetch data from it. Should I create a class in data browser using the unique id of us

Solution 1:

Assuming the use of the Rest API , a minimum prerequisite to exclusive READ/WRITE for a specific parse user would be to do follow:

create new user according to the parse docs with POST to users table...

  -d '{"username":"yourName","password":"e8"}'  https://api.parse.com/1/users

get the response from above request and parse the OID of the new user and the TOKEN value in the response. Persist them in your app to a durable 'user_prefs' type for future use with something like...

PreferenceManager.getDefaultSharedPreferences(myActivity).edit().put....

When you want to Write objects for that user do the following:

include in headers,

"X-Parse-Session-Token: pd..."// the token you saved

include ACL tag in json for POST of the parse class/object that you are writing...

the user OID within the ACL tag should be the OID value from the response when you created the new parse user

 -H "X-Parse-Session-Token: pdqnd......." \
  -d '{"ACL": {"$UserOID": {
    "read": true,
    "write": true
  }}}' \
  https://api.parse.com/1/classes/MyClass

READS:

Because the ACL for every object written to MyClass is exclusive to the user in '$UserOID, noone else can see them. As long as you include the token value in a header with any read, $UserOID will be the only one with access. The token value, originally returned when you created the new user is logically bound to the userOID and can be used in the header in kind of magic way... No server-session required on the device when the app starts, no explicit user authentication step required to the server, no query expression in a GET - simply provide the token value in the header layer and request all records(all users) it works to get records for just the userID inferred from the token value in the header. On init, the app just has to retrieve the token from 'shared_prefs' on the client side. Server side, the token lease is permanent.

 -H "X-Parse-Session-Token: pdqnd......."

include above with every GET. -H "X-Parse-Session-Token: pdqnd......." You will be the only parse user who can see them...

if you want multiple devices bound to one parse user, this is NG. if you want multiple parse accounts to be accessed from one instance of the app, this is NG.

Solution 2:

You have to use relations. First, create a new column (not in your user's class) and the type is a relation, the relation is to the user class. Lets say you want to add a new post. Use this:

ParseObjectpost= ...;

ParseUseruser= ParseUser.getCurrentUser();
ParseRelationrelation= user.getRelation("posts");
relation.add(yourString);
user.saveInBackground();

Code source

Tell me and I will edit this if you don't understand.

Solution 3:

I guess you want something like for (to store some specific data for a particular parse user)

var note = newNoteOb();
        note.set("text", text);
        note.set("creator", currentUser);
        note.setACL(newParse.ACL(currentUser));

        note.save(null, {
            success:function(note) {
                $("#newNoteText").val("");
                getMyNotes();
            }, error:function(note, error) {
                //Should have something nice here...
            }
        });

And for: I want to fetch data from it

functiongetMyNotes() {
    var query = newParse.Query(NoteOb);
    query.equalTo("creator", currentUser);
    query.find({
        success:function(notes) {
            var s = "";
            for(var i=0, len=notes.length; i<len; i++) {
                s+= "<p>"+notes[i].get("text")+"</p>";
            }
            $("#currentNotes").html(s);
        }
    });
}

Check out this blog , it will give you a better understanding.

Post a Comment for "How To Store Some Particular Data For Some Particular Parse User In Android"