I use parse AnyPhone for Login using mobile number and after successfully login (OTP verification), i want to get all parse user from User table for that i used bellow query but i only get Login user Data not all. Thanks in Advance.
ArrayList<String> Email = new ArrayList<String>();
Email.add("test2#gmail.com");
Email.add("test#g.com");
Email.add("test#gmail.com");
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereContainedIn("email", Email);
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if(e==null){
Log.i("Size",""+objects.size());
}
}
});
void getAllParseUser() {
ParseUser user = ParseUser.getCurrentUser();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo(ParseTableConstants.OBJECT_ID, user.getObjectId());
progressBar.showProgress();
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
insertData(objects);
} else {
// Something went wrong.
progressBar.hideProgress();
}
}
});
}
This code will give you all parse user
I solved My Problem by setting ACL in javascript File.Now i am getting all the Users.
var acl = new Parse.ACL();
// public can read
acl.setPublicReadAccess( true );
// public cannot write
acl.setPublicWriteAccess( false );
// user can read data
acl.setReadAccess( user.id, true );
// user can write data
acl.setWriteAccess( user.id, false );
user.setACL(acl);
user.save();
Related
I've searched everywhere but haven't found anything about how to check if a username/email address in the parse database is taken. I've found some answers on the internet on parse.com forums but they weren't clear.
Thanks if you could help.
If this has an answer somewhere, then please comment instead of marking so I can delete it.
I think this will do what you need if I understand your question correctly:
final ParseQuery<ParseUser> emailQuery = ParseUser.getQuery();
emailQuery.whereEqualTo("email", emailAddress);
final ParseQuery<ParseUser> usernameQuery = ParseUser.getQuery();
usernameQuery.whereEqualTo("email", username);
List<ParseQuery> queries = new ArrayList<>();
queries.add(emailQuery);
queries.add(usernameQuery);
final ParseQuery<ParseUser> query = ParseQuery.or(queries);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> results, ParseException e) {
// results has the list of users that match either the email address or username
}
});
https://www.parse.com/docs/android/guide#queries-compound-queries
Or you could do it this way:
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// yippee!!
} else {
switch (e.getCode()) {
case ParseException.USERNAME_TAKEN: {
// report error
break;
}
case ParseException.EMAIL_TAKEN: {
// report error
break;
}
default: {
// Something else went wrong
}
}
}
}
});
Try this to check your data in parse. I hope this will helpful for you.
// this is create query of your parse table
ParseQuery<ParseObject> query = new ParseQuery<>(your prars tableName);
query.whereEqualTo(YourParseColumeNameEmail, yourEmail);
query.whereEqualTo(YourParseColumeNamePassword, yourPassword);
// this is for doing in background
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
if (scoreList.size() == 0) {
// if there is no data like your email and password then it,s come here
} else {
// if there is data like your email and password then it,s come here
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
In Parse I have another column in the User table known as 'Friends' which is an array. From my current user I am trying to add to another user's friends array.
I have tried:
//buddy = a string of the other person's username
//to add to CURRENT user's array (this is working)
UserList.user.addUnique("Friends", buddy);
UserList.user.saveEventually();
//this is to add to another user's array (NOT WORKING)
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", buddy);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
for (ParseObject friend : objects) {
friend.addUnique("Friends",UserList.user.getUsername());
friend.saveEventually();
}
} else {
// Something went wrong.
Log.d("Username", "Error: " + e.getMessage());
}
}
});
Write a method in a java that passes data to the cloud, and calls the function on the cloud by its name:
// the passes to the cloud is stored on HashMap
HashMap<String, Object> params = new HashMap<String, Object>();
// user's name to add the buddy to it
params.put("username", username);
// buddy's name to pass to the cloud
params.put("buddy", buddy);
ParseCloud.callFunctionInBackground("addBuddyToFriendsList", params, new FunctionCallback<String>(){
public void done(String result, ParseException e){
// e==null means no errors in running the function
if(e==null){
System.out.println(result);
}else{
System.out.println(e.getMessage());
}
}
});
Ok, and now let's write the function to be used in the cloud (assuming you know how to deploy functions on the cloud):
[EDITED]
Parse.Cloud.define("addBuddyToFriendsList", function (request, response){
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("username", request.params.username);
query.find({
success: function(user) {
// query.find returns an array.....
user[0].addUnique("Friends", request.params.buddy);
user[0].save(null, {
success: function(success){
response.success();
},
error: function (error){
response.error(error);
}
});
},
error: function(object, error) {}
});
});
Try this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
query.whereEqualTo("username", buddy);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
// The query was successful.
for (ParseObject friend : objects) {
friend.addUnique("Friends",UserList.user.getUsername());
friend.saveEventually();
}
} else {
// Something went wrong.
Log.d("Username", "Error: " + e.getMessage());
}
}
});
I tried to call that class in different way then you did, I referred to it like a normal class. Usually this way works for me.
The thing is with "ParseUser" type is limited, for security reasons.
I am using ParseUser for user management. Having the username (unique), I planned to query the User class to identify the user and then put a new score to the "score" field, just like a Leaderboard. Coded as follows:
Code:
public void update_user_score(String username, int original_score, int add)
{
final int new_score = original_score + add;
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", username);
query.setLimit(1);
query.findInBackground(new FindCallback()
{
public void done(final ParseObject object, ParseException e)
{
if (e == null)
{
object.saveInBackground(new SaveCallback()
{
public void done(ParseException e)
{
object.put("score", new_score);
object.saveInBackground();
onBackPressed();
}
});
}
}
});
}
Situation:
It states that The type new FindCallback(){} must implement the inherited abstract method FindCallback.done(List, ParseException) . I have tried that FindCallback.done and found it unsucessful.
Question:
I would like to ask how the other fields of the user be updated with the username given? Thanks!
As per the parse documentation said,
The ParseUser class is secured by default. Data stored in a ParseUser can only be modified by that user. By default, the data can still be read by any client. Thus, some ParseUser objects are authenticated and can be modified, whereas others are read-only.
Specifically, you are not able to invoke any of the save or delete type methods unless the ParseUser was obtained using an authenticated method, like logIn or signUp. This ensures that only the user can alter their own data.
The following illustrates this security policy:
ParseUser user = ParseUser.logIn("my_username", "my_password");
user.setUsername("my_new_username"); // attempt to change username
user.saveInBackground(); // This succeeds, since the user was authenticated on the device
// Get the user from a non-authenticated manner
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getInBackground(user.getObjectId(), new GetCallback<ParseUser>() {
public void done(ParseUser object, ParseException e) {
object.setUsername("another_username");
// This will throw an exception, since the ParseUser is not authenticated
object.saveInBackground();
}
});
please go through this link Reference
public void update_user_score(String username, int original_score, int add)
{
final int new_score = original_score + add;
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", username);
query.setLimit(1);
query.findInBackground(new FindCallback()
{
public void done(final ParseUser object, ParseException e)
{
if (e == null)
{
object.put("score", new_score);
object.saveInBackground(new SaveCallback()
{
public void done(ParseException e)
{
if(e==null)
onBackPressed();
}
});
}
}
});
}
As far as I understand from your question is; you want to find the user entry in user table via using the specified user id and update the score field. First suggestion, instead of findInBackground use getFirstInBackground. Following that check the returned user object if not null perfrom the user update operation. Then call saveInBackground. saveInBackground is used for perfroming actions when the save is succesful. In your code, I see that you try to save the object in done method again. Also, one suggestion is that control the ACL.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getFirstInBackground(someUserId, new GetCallback<ParseUser>() {
public void done(ParseUser user, ParseException e) {
if (e == null) {
// No error e is null
// check user object
if (user == null) {
// no user , error
} else {
// perfrom save operation
// put score field
// call save in background
// in done method update UI for example.
}
} else {
// Something went wrong.
}
}
});
I have the objectID of a particular user (who is not the current user) and would like to find his Display Name, which is a custom field that I created.
As per Parse's guide, this code will create a list of users that match some particular attributes.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("gender", "female");
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
} else {
// Something went wrong.
}
}
});
There's no reason for me to make a list, however, if only one user has that objectID. Any way for me to just get the display name of a particular user?
What you want instead is getFirstInBackground(), e.g.:
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getFirstInBackground(someUserId, new GetCallback<ParseUser>() {
public void done(ParseUser user, ParseException e) {
if (e == null) {
// The query was successful.
// check if we got a match
if (user == null) {
// no matching user!
} else {
// great, get the name etc
}
} else {
// Something went wrong.
}
}
});
Hi I was wondering why this code does not work. I am trying to query a ParseUser's username field to find a certain user but it keeps saying that it cant find it.
private void findUserName(String user) {
// query the User database to find the passed in user
ParseQuery query = ParseUser.getQuery();
query.whereEqualTo("username", user);
query.findInBackground(new FindCallback() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
foundUser = (objects.size() != 0);
}
});
}
Here is my method that calls it
if (!foundUser) {
errorMessage.setText("Invalid user name");
}
foundUser is a field because I couldnt return it in the method...
Parse treats User objects separate from Parse objects. You should use List<ParseUser> instead of List<ParseObject>. The Parse Android Guide provides an example https://parse.com/docs/android_guide#users-querying.
Here is the Parse example with your where clause.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", user);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
} else {
// Something went wrong.
}
}
});
İf you want to get current user this may be helpful;
String currentUser = ParseUser.getCurrentUser().getUsername();