New to Parse, not able to sign up a ParseUser - android

I am just following the basic Parse quickstart guide found here:
https://www.parse.com/apps/quickstart#social/mobile/android/native/new
Everything compiled and ran just fine, but I checked and found that no user was actually being signed up on Parse. I checked the log and here is the error I am getting:
PARSE.COMīš• FAILEDjava.lang.IllegalArgumentException: Cannot save a ParseUser until it has been signed up. Call signUp first.-1
Here is the code I am working with. As you can see, I just copied the tutorial exactly with the addition of outputting to the Log.
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Initialize Crash Reporting.
ParseCrashReporting.enable(this);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(this, "myappid", "mykey");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email#example.com");
// other fields can be set just like with PareObject
user.put("phone", "650-555-0000");
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Log.e("PARSE.COM", "SUCCESS");
} else {
Log.e("PARSE.COM","FAILED" + e.getMessage() + Integer.toString(e.getCode()));
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
}
}
I don't understand why the error is prompting me to call signUp first, is that not exactly I am doing with signUpInBackground? Any help would be greatly appreciated.

it looks like a same bug.
https://developers.facebook.com/bugs/426365424187686/
if you delete "Parse.enableLocalDatastore(this);" it will be work fine.
(API level doesn't matter)
and.. they assured me that they will fix the bug with next release.
but despite of updates(1.8.2->1.9.0) it is remained yet.
i'm sorry about my broken english.

Related

Parse whereEqualsTo not working in android

I'm trying to use Parse in a personal project but I faced a problem when I tried to get data from a new object called "Image". What I'm trying to do is from a list of users select one and display all the images related to the selected user, If I remove the whereEqualsTo I receive the images related to the user I'm login in. If I put whereEqualsTo I receive nothing.
This is my code:
private void getUserImages(final String selectedUserName) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
query.whereEqualTo("username", selectedUserName);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0){
//Do something
}
}
}
});
}
This is my config class:
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("202ac01cxxxxxxxxxxa41d1136bc8a86213328b4")
.clientKey("76b883b596xxxxxxxxxf60f9352fdb926dde46e")
.server("http://ec2-xx-xx-xxx-59.us-east-2.compute.amazonaws.com:80/parse/")
.build());
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
Someone has any idea, how can I fix this?
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.
For any object, you can specify which users are allowed to read the object, and which users are allowed to modify an object. To support this type of security, each object has an access control list, implemented by the ParseACL class.
See this documentation on how to set Access Control list and give specific permissions.Parse User documentation

Issue while querying for singing up the user "this authentication method is unsupported"

i did the migration process for using the parse platform locally. i have deployed the parse-server-example on my localhost and hosted the DB on mongolab. First step is i am trying to register the user using the local parse server and on the DB instance hosted on mongolab.
This is the index.js of locally deployed parse server, and the following is the code snippet for android.
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Stetho.initializeWithDefaults(this);
// Add your initialization code here
//Parse.initialize(this);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("my app id")
.clientKey("my client key")
.server("http://10.12.41.250:1337/parse/") // '/' important after 'parse'
.addNetworkInterceptor(new ParseStethoInterceptor())
.build());
....
....
final ParseUser parseUser = new ParseUser();
parseUser.setUsername(edtUsername.getText().toString());
parseUser.setPassword(edtPassword.getText().toString());
parseUser.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(SignUpActivity.this, "You are now registered.", Toast.LENGTH_SHORT).show();
//Success
} else {
Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
//Failure
}
}
});
Upon executing this i am getting ParseRequestException with error message "this authentication method is unsupported", now i don't know what is it about and only thing that i found so far is This.
The following is the detail of network interceptor.
Any kind of help would be greatly appreciated.
So, That was an issue and it's Fixed now.

"Cannot save a ParseUser that is not authenticated" with authenticated user

I'm using Parse as my backend and I'm trying to "like" a post that another user posted on the app. I'm querying to get the post, then incrementing the number of likes by 1, then adding the current user's object ID to an array that holds all the ID's of users which liked the post.
carLikeQuery.getInBackground(carItem.getObjectId(), new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
object.increment("likes");
object.addUnique("usersWhoLike", ParseUser.getCurrentUser().getObjectId());
object.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if(e==null) {
Log.d("SAVE", "Like saved :)");
} else {
Log.e("SAVE", "Not saved :( :" + e.getLocalizedMessage());
}
}
});
}
});
The error I'm getting:
E/SAVE: Not saved :( :java.lang.IllegalArgumentException: Cannot save a ParseUser that is not authenticated.
I saw the source code for the ParseUser from somewhere:
void validateSave() {
if (getObjectId() == null) {
throw new IllegalArgumentException("Cannot save a ParseUser until it has been signed up. Call signUp first.");
}
if (!isAuthenticated() && isDirty()) {
throw new IllegalArgumentException("Cannot save a ParseUser that is not authenticated.");
}
}
Doing the same kind of checking in my code reveals that the the currentUser is AUTHENTICATED and NOT DIRTY.
What could the issue be? To be honest, I want to say that it was working just fine before today, but obviously I was changing something and made a mistake down the line and I can't find it! Any help would be greatly appreciated.
I resolved the issue by creating an entirely new Parse application with the same data structure/layout. It just plain worked without any code changes.
You can follow the issue on GitHub here

ParseUser unable to be logged in after migrating to MongoLab

So I'm rebuilding an Android app after grieving the shutdown of Parse, and am trying to lean on Heroku and MongoLab to host my data as outlined in this tutorial.
I've been able to save and read custom objects as well as save new ParseUser objects. I just can't successfully log users in (which I was able to do previously with just Parse).
Here is a snippet of my code, after I've enabled local datastore and initialized Parse:
ParseUser.logInInBackground(username.getText().toString(), password.getText().toString(),
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Intent intent = new Intent(
MainActivity.this,
Dashboard.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exists, please signup",
Toast.LENGTH_LONG).show();
}
}
});
Running this doesn't throw any errors, but the user is not logged in and the "No such user exists, please signup" toast is shown.
Does MongoLab somehow encrypt the passwords in a way that ParseUser's login methods can't read? If you have any ideas on what the issue could be, please let me know.
I was running into the same issue. My problem ended up being the fact that I built my Android app pointing to localhost instead of to the actual IP address where my instance of Parse Server was running.
My initial (faulty) code:
Parse.initialize(
new Parse.Configuration.Builder(getApplicationContext())
.applicationId(PARSE_APPLICATION_ID)
.clientKey(PARSE_CLIENT_KEY)
.server("http://localhost:1337/parse/") // HERE
.build());
Which works with the correct IP address:
Parse.initialize(
new Parse.Configuration.Builder(getApplicationContext())
.applicationId(PARSE_APPLICATION_ID)
.clientKey(PARSE_CLIENT_KEY)
.server("http://192.168.1.9:1337/parse/") // HERE
.build());

Android setReadAccess for Parse ADMIN error

I use a Parse database. I would like to have access for simple users and an admin user. The would be that each user could see only his/her own data but the admin user could see all of users' data.
I create a ParseUser, and if the current user is equal with it, it should be known it is the admin user.
I get the following error:
java.lang.IllegalArgumentException: cannot setReadAccess for a user with null id
I think the mistakes are with if function (never become true) and this: acl.setReadAccess(ADMIN,true);
Could anyone suggest something?
ParseUser ADMIN = new ParseUser();
ADMIN.setUsername("ADMIN3");
ADMIN.setPassword("a");
// Create a post.
AnywallPost post = new AnywallPost();
// Set the location to the current user's location
post.setLocation(geoPoint);
post.setText(text);
post.setUser(ParseUser.getCurrentUser());
ParseACL acl = new ParseACL();
// Give read accesses
if (ParseUser.getCurrentUser() == ADMIN) {
acl.setReadAccess(ParseUser.getCurrentUser(), true);
}
else
{
acl.setReadAccess(ParseUser.getCurrentUser(),true);
acl.setReadAccess(ADMIN,true);
}
post.setACL(acl);
// Save the post
post.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
dialog.dismiss();
finish();
}
});

Categories

Resources