I was using Parse with AWS hosting at first for my application but later when Parse shut down their service I moved to back4app. My Login and Signup used to work fine with the previous Parse project but now whenever I Login or Signup with my back4app project, I get the error com.parse.ParseRequest$ParseRequestException: unauthorized. I have tried using Client Key and Master Key both but they don't seem to work at all.
Here's my Signup Code:
public void clickSignup(View view) {
ParseUser.logOut();
loader = (ProgressBar) findViewById(R.id.loadingBar);
loader.setVisibility(View.VISIBLE);
ParseQuery checkAvailability = ParseUser.getQuery();
textUser = (EditText) findViewById(R.id.textUser);
textPass = (EditText) findViewById(R.id.textPass);
if (textUser.getText().toString().isEmpty() || textPass.getText().toString().isEmpty()) {
loader.setVisibility(View.INVISIBLE);
Toaster("Enter a valid username/password");
} else if (textUser.getText().length() < 4){
Toaster("Username must have four or more characters");
loader.setVisibility(View.INVISIBLE);
} else if (textPass.getText().length() < 6) {
Toaster("Password mush have atleast six or more characters");
loader.setVisibility(View.INVISIBLE);
}else{
String user = textUser.getText().toString();
Log.i("user", user);
checkAvailability.whereEqualTo("username" , user);
checkAvailability.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null && objects.size() == 1){
loader.setVisibility(View.INVISIBLE);
Toaster("This username already exists");
} else if (e == null && objects.size() != 1){
loader.setVisibility(View.INVISIBLE);
ParseUser newUser = new ParseUser();
newUser.setUsername(textUser.getText().toString());
newUser.setPassword(textPass.getText().toString());
newUser.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
Log.i("S", "Seucbbkw");
Log.i("e", e.toString());
if (e == null){
Intent intent = new Intent(getApplicationContext(), LoggedIn.class);
intent.putExtra("Username",textUser.getText().toString() );
startActivity(intent);
Toaster("Signup Successful");
}
}
});
} else {
Log.i("Objects", e.toString());
}
}
});
}
}
and here's my Login Code:
public void clickSignin(View view){
ParseUser.logOut();
textUser = (EditText) findViewById(R.id.textUser);
textPass = (EditText) findViewById(R.id.textPass);
loader.setVisibility(View.VISIBLE);
if (textUser.getText().toString().isEmpty() || textPass.getText().toString().isEmpty()) {
loader.setVisibility(View.INVISIBLE);
Toaster("Enter a valid username/password");
} else {
final ParseQuery logInner = ParseUser.getQuery();
logInner.whereEqualTo("username", textUser.getText().toString());
ParseUser.logInInBackground(textUser.getText().toString(), textPass.getText().toString(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), LoggedIn.class);
intent.putExtra("Username",textUser.getText().toString() );
startActivity(intent);
Toaster("Login Successful");
loader.setVisibility(View.INVISIBLE);
} else {
Toaster("Invalid username or password");
Log.i("Error", e.toString());
loader.setVisibility(View.INVISIBLE);
}
}
});
}
}
(Just for tests) I recommend that you use the appID too to connect at Back4App! For example the code below:
<resources>
<string name="back4app_server_url">https://parseapi.back4app.com/</string>
<!-- Change the following strings as required -->
<string name="back4app_app_id">PASTE_YOUR_APPLICATION_ID_HERE</string>
<string name="back4app_client_key">PASTE_YOUR_CLIENT_KEY_HERE</string>
<string name="back4app_master_key">PASTE_YOUR_MASTER_KEY_HERE</string>
<string name="app_name">QuickstartExampleApp</string>
Related
I am developing an app which has signup and Login using parse server,in which i am able to signup but when i try to login it gives me exception
"Invalid username/password"
This is the code for signUp and LogIn,when the signUpMode is active the user is signedup on pressing the button alternatively when signUpmode is deactive i.e false the button acts as Login and the user can login but here when i try to login its saying "Invalid Username/password"
public void signUp(View view)
{
editTextUser =(EditText) findViewById(R.id.userNameEdit);
editTextPass =(EditText) findViewById(R.id.passWordEdit);
if(editTextUser.getText().toString().matches("") || editTextPass.getText().toString().matches(""))
{
Toast.makeText(this,"Username and Password required",Toast.LENGTH_SHORT).show();
}
else
{
if(SignupModeActive)
{
ParseUser user = new ParseUser();
user.setUsername(editTextUser.getText().toString());
user.setPassword(editTextUser.getText().toString());
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if(e == null)
{
Log.i("saveInBackGround","SignUp Success");
Intent intent = new Intent(MainActivity.this,UserslistActivity.class);
startActivity(intent);
}
else{
Toast.makeText(MainActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
}
else
{
ParseUser.logInInBackground(editTextUser.getText().toString(),editTextPass.getText().toString(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if(user != null){
Log.i("LogInBackGround","Login Succesfull");
Intent logInintent = new Intent(MainActivity.this,UserslistActivity.class);
startActivity(logInintent);
}
else
{
Toast.makeText(MainActivity.this,e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
}
}
//Check your Exception
public void signUp(View view)
{
mEditTextUser =(EditText) findViewById(R.id.userNameEdit);
mEditTextPass =(EditText) findViewById(R.id.passWordEdit);
if(mEditTextUser .getText().toString().trim().length()==0 || editTextPass.getText().toString().trim().length()==0.matches(""))
{
Toast.makeText(this,"Username and Password required",Toast.LENGTH_SHORT).show();
}
else
{
//Check SignupMode is true
if(SignupModeActive)
{
ParseUser user = new ParseUser();
user.setUsername(editTextUser.getText().toString());
user.setPassword(editTextUser.getText().toString());
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if(e == null)
{
Log.e("Exception",e.printStackTrace());
Intent intent = new Intent(MainActivity.this,UserslistActivity.class);
startActivity(intent);
}
else{
Toast.makeText(MainActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
}
else
{
ParseUser.logInInBackground(editTextUser.getText().toString(),editTextPass.getText().toString(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if(user != null){
Log.i("LogInBackGround","Login Succesfull");
Intent logInintent = new Intent(MainActivity.this,UserslistActivity.class);
startActivity(logInintent);
}
else
{
Toast.makeText(MainActivity.this,e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
}
}
Your codes for login is okay i will say u check whether the details you are feeding is true or not. Maybe their isn't any user with that name or password u feed is wrong .
I am using similar codes and it works fine. my codes are :-
ParseUser.logInInBackground(edtEmail.getText().toString(),
edtPassword.getText().toString(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (user != null && e == null) {
FancyToast.makeText(Login.this, user.get("username") + " is logged in successfully", FancyToast.LENGTH_LONG, FancyToast.SUCCESS, true).show();
transitionToWelcomePage();
} else {
FancyToast.makeText(Login.this, e.getMessage(), FancyToast.LENGTH_LONG, FancyToast.ERROR, true).show();
}
}
});
Currently, I am using this tutorial to create the facebook login.
"https://github.com/ParsePlatform/ParseUI-Android"
The Parse user JSON didn't return me an email or gender. I also have research around but I still can't find the solution (well, at least, some other still returning null). Anyone can explain the reason and how to solve it?
facebookLoginButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
loadingStart(false); // Facebook login pop-up already has a spinner
if (config.isFacebookLoginNeedPublishPermissions()) {
ParseFacebookUtils.logInWithPublishPermissionsInBackground(getActivity(),
Arrays.asList(
"public_profile", "email"), facebookLoginCallbackV4);
Log.i("fbUser","Publish");
} else {
ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(),
Arrays.asList( "public_profile", "email"), facebookLoginCallbackV4);
Log.i("fbUser", "Read");
}
}
});
private LogInCallback facebookLoginCallbackV4 = new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (isActivityDestroyed()) {
return;
}
if (user == null) {
loadingFinish();
if (e != null) {
showToast(R.string.com_parse_ui_facebook_login_failed_toast);
debugLog(getString(R.string.com_parse_ui_login_warning_facebook_login_failed) +
e.toString());
}
} else if (user.isNew()) {
GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject fbUser,
GraphResponse response) {
/*
If we were able to successfully retrieve the Facebook
user's name, let's set it on the fullName field.
*/
ParseUser parseUser = ParseUser.getCurrentUser();
if (fbUser != null && parseUser != null && fbUser.optString("name").length() > 0) {
Log.i("FbUSer", response.getJSONObject().toString());
Log.d("FbUSer-Email",fbUser.optString("email"));
Log.i("FbUSer-gender",fbUser.optString("gender"));
parseUser.put(USER_OBJECT_NAME_FIELD, fbUser.optString("name"));
parseUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
debugLog(getString(
R.string.com_parse_ui_login_warning_facebook_login_user_update_failed) +
e.toString());
}
loginSuccess();
}
});
}
loginSuccess();
}
}
).executeAsync();
} else {
loginSuccess();
}
}
};
Logcat Section return:
{"id":"1234524124124","name":"FbUser NAme"}
I just found the answer. I just need to set the parameter so I can get the data I want.
GraphRequest request = GraphRequest.newMeRequest(...);
Bundle parameters = new Bundle();
parameters.putString("fields","id,name,link,email,first_name,last_name,gender");
request.setParameters(parameters);
request.executeAsync();
Reference: https://stackoverflow.com/a/32579366/4961962
for more user info you have to add permissoin to access those detail like email, user_about_me at facebook developer console
select app at facebook developer and go -> app details -> Configure
App Center Permissions
i'm tryng to integrate facebook login in my android application. For now i get a new row in Parse Backend about the logged user which contains his real name, some weird value(ex:SnvvKEsIv6tX7...) in his userName, and an authData which is Json and contains the following values:
access_token, expiration date, id.
After debugging i got the url of the json response, it only contains two values, the name and the id, however i declared the list like this:
List permissions = Arrays.asList("public_profile", "email");
So for now the graph is only returnin two values, i thought it was due to the permissions but as i sayed i did declared. Here is my code:
public class LoginActivity extends Activity {
private Dialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FacebookSdk.sdkInitialize(getApplicationContext());
ParseFacebookUtils.initialize(this);
// Check if there is a currently logged in user
// and it's linked to a Facebook account.
ParseUser currentUser = ParseUser.getCurrentUser();
if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) {
// Go to the user info activity
showUserDetailsActivity();
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
public void onLoginClick(View v) {
progressDialog = ProgressDialog.show(LoginActivity.this, "", "Logging in...", true);
List<String> permissions = Arrays.asList("public_profile", "email");
// NOTE: for extended permissions, like "user_about_me", your app must be reviewed by the Facebook team
// (https://developers.facebook.com/docs/facebook-login/permissions/)
ParseFacebookUtils.logInWithReadPermissionsInBackground(this, permissions, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException err) {
progressDialog.dismiss();
if (user == null) {
Log.d("TAG", "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject fbUser,
GraphResponse response) {
/*
* If we were able to successfully retrieve the
* Facebook user's name, let's set it on the
* fullName field.
*/
Log.e("facebook User", fbUser.toString());
final ParseUser parseUser = ParseUser
.getCurrentUser();
if (fbUser != null
&& parseUser != null
&& fbUser.optString("name").length() > 0) {
parseUser.put("name",
fbUser.optString("name"));
parseUser.put("email",
fbUser.optString("email"));
Log.v("isnew, values: ","values : "+fbUser.optString("name")+","+fbUser.optString("email")+","+fbUser.optString("age_range")+","+fbUser.optString("locale"));
parseUser
.saveInBackground(new SaveCallback() {
#Override
public void done(
ParseException e) {
if (e != null) {
Log.v("", (getString(R.string.com_parse_ui_login_warning_facebook_login_user_update_failed)
+ e.toString()));
}
ParseInstallation installation = ParseInstallation
.getCurrentInstallation();
installation
.put(ParseConstants.KEY_USER_ID,
parseUser
.getUsername());
installation
.saveInBackground();
showUserDetailsActivity();
}
});
}
}
}).executeAsync();
} else {
Log.d("TAG", "User not new logged in through Facebook!");
showUserDetailsActivity();
}
}
});
}
private void showUserDetailsActivity() {
Intent intent = new Intent(this, UserDetailsActivity.class);
startActivity(intent);
}
}
public class UserDetailsActivity extends Activity {
private ProfilePictureView userProfilePictureView;
private TextView userNameView;
private TextView userGenderView;
private TextView userEmailView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userdetails);
userProfilePictureView = (ProfilePictureView) findViewById(R.id.userProfilePicture);
userNameView = (TextView) findViewById(R.id.userName);
userGenderView = (TextView) findViewById(R.id.userGender);
userEmailView = (TextView) findViewById(R.id.userEmail);
//Fetch Facebook user info if it is logged
ParseUser currentUser = ParseUser.getCurrentUser();
if ((currentUser != null) && currentUser.isAuthenticated()) {
makeMeRequest();
}
}
#Override
public void onResume() {
super.onResume();
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// Check if the user is currently logged
// and show any cached content
updateViewsWithProfileInfo();
} else {
// If the user is not logged in, go to the
// activity showing the login view.
startLoginActivity();
}
}
private void makeMeRequest() {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
if (jsonObject != null) {
JSONObject userProfile = new JSONObject();
try {
userProfile.put("facebookId", jsonObject.getLong("id"));
userProfile.put("name", jsonObject.getString("name"));
if (jsonObject.getString("gender") != null)
userProfile.put("gender", jsonObject.getString("gender"));
if (jsonObject.getString("email") != null)
userProfile.put("email", jsonObject.getString("email"));
// Save the user profile info in a user property
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.put("profile", userProfile);
currentUser.saveInBackground();
// Show the user info
updateViewsWithProfileInfo();
} catch (JSONException e) {
Log.d("TAG",
"Error parsing returned user data. " + e);
}
} else if (graphResponse.getError() != null) {
switch (graphResponse.getError().getCategory()) {
case LOGIN_RECOVERABLE:
Log.d("TAG",
"Authentication error: " + graphResponse.getError());
break;
case TRANSIENT:
Log.d("TAG",
"Transient error. Try again. " + graphResponse.getError());
break;
case OTHER:
Log.d("TAG",
"Some other error: " + graphResponse.getError());
break;
}
}
}
});
request.executeAsync();
}
private void updateViewsWithProfileInfo() {
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser.has("profile")) {
JSONObject userProfile = currentUser.getJSONObject("profile");
try {
if (userProfile.has("facebookId")) {
userProfilePictureView.setProfileId(userProfile.getString("facebookId"));
} else {
// Show the default, blank user profile picture
userProfilePictureView.setProfileId(null);
}
if (userProfile.has("name")) {
userNameView.setText(userProfile.getString("name"));
} else {
userNameView.setText("");
}
if (userProfile.has("gender")) {
userGenderView.setText(userProfile.getString("gender"));
} else {
userGenderView.setText("");
}
if (userProfile.has("email")) {
userEmailView.setText(userProfile.getString("email"));
} else {
userEmailView.setText("");
}
} catch (JSONException e) {
Log.d("TAG", "Error parsing saved user data.");
}
}
}
public void onLogoutClick(View v) {
logout();
}
private void logout() {
// Log the user out
ParseUser.logOut();
// Go to the login view
startLoginActivity();
}
private void startLoginActivity() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
i'm using Parse 1.9.4 and ParseFacebookUtils 1.9.4.
I'm trying to make an android app using parse that allows one to login using either their username or email. I have tried querying to get an object with a provided email address, then get that object's username to login with. However, I am getting this error:
'getFirstInBackground(com.parse.GetCallback)' in 'com.parse.ParseQuery' cannot be applied to '(anonymous com.parse.GetCallback "com.parse.ParseObject>)'
I'm new to app dev and parse, so I'm not entirely sure what this means. From what I understand it wont let me use getFirstInBackground because that works with parseUser's and I'm working with ParseObjects, but the code I'm using I pulled from a prior stackoverflow question where this was a working answer: Login username AND email in Parse Android
Here is my code:
// Do this to allow for username or email log in
if (mEmail.indexOf("#") != -1) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("email", mEmail);
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("score", "The getFirst request failed.");
} else {
String actualUsername = object.getString("username");
ParseUser.logInInBackground(actualUsername, mPassword, new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
if (e != null) {
// TODO: Show error message
Toast.makeText(LoginActivity.this, "Credentials incorrect", Toast.LENGTH_LONG).show();
} else {
// Start Intent for activity
// TODO: Choose activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
}
});
}
}
});
According to docs, the method's signature is as follows:
class com.parse.ParseQuery<T> {
public void getFirstInBackground(GetCallback<T> callback)
}
That means that the generic type of GetCallback must be the same as in your ParseQuery. So it probably should be
query.getFirstInBackground(new GetCallback<ParseUser>()) { /* ... */ }
You are attempting to query a ParseUser with a GetCallBack of type ParseObject.
Replace all instances of ParseObject with ParseUser in your code.
query.getFirstInBackground(new GetCallback<ParseUser>() {
public void done(ParseUser user, ParseException e) {
if (object == null) {
Log.d("score", "The getFirst request failed.");
} else {
String actualUsername = user.getUsername();
ParseUser.logInInBackground(actualUsername, mPassword, new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
if (e != null) {
// TODO: Show error message
Toast.makeText(LoginActivity.this, "Credentials incorrect", Toast.LENGTH_LONG).show();
} else {
// Start Intent for activity
// TODO: Choose activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
}
});
}
}
});
Hope this helps
final String userOrEmal = editTextEmailOrUserName.getText().toString().trim();
final String mpassword = editTextPassword.getText().toString().trim();
if (userOrEmal.contains("#")) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("email", userOrEmal);
query.getFirstInBackground(new GetCallback<ParseUser>() {
#Override
public void done(ParseUser object, ParseException e) {
if (object != null) {
ParseUser.logInInBackground(object.getString("username"), mpassword, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.v("login", "secessful");
} else {
Log.v("login", "fail");
}
}
});
} else {
}
}
});
} else {
ParseUser.logInInBackground(userOrEmal,mpassword, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.v("login", "secessful");
} else {
Log.v("login", "fail");
}
}
});
}
I am working on an application using Parse.com as backend support.I have used ParseUser for login and signup ,but now I have to implement change Password and forgot password ,but don't know how to implement it..Please help me to implement this functionalities.
The code which I have used to login the ParseUser is as follows:
ParseUser.logInInBackground(str_email2, str_password2, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
dlg.dismiss();
if(e == null)
{
Log.d(">>>","ObjId>>"+user.getObjectId()+" Username>>>"+user.getUsername());
}
else
loginUnSuccessful();
}
});
To request a new password (in case the user forgot it) you can use this:
ParseUser.requestPasswordResetInBackground("myemail#example.com",
new RequestPasswordResetCallback() {
public void done(ParseException e) {
if (e == null) {
// An email was successfully sent with reset instructions.
} else {
// Something went wrong. Look at the ParseException to see what's up.
}
}
});
And to change a password you can just get the current user and do the following:
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.setPassword("new_password");
currentUser.saveInBackground();
In the doc, you have this sample code:
ParseUser.requestPasswordResetInBackground("myemail#example.com",
new RequestPasswordResetCallback() {
public void done(ParseException e) {
if (e == null) {
// An email was successfully sent with reset instructions.
} else {
// Something went wrong. Look at the ParseException to see what's up.
}
}
});
Source: https://parse.com/docs/android_guide#users-resetting
You can not reset the password for not signed (anonymous) ParseUser.
If you are using email feature for ParseUser, you can send password reset mail like this
ParseUser.requestPasswordResetInBackground(
stringEmail,
new RequestPasswordResetCallback() {
public void done(ParseException e) {
...
}
}
);
If you are not using email feature, you need to write a cloud method in your main.js file, like this
Parse.Cloud.define("resetPassword", function (request, response) {
Parse.Cloud.useMasterKey(); /*important*/
var username = request.params.username;
var password = request.params.password;
var objUser = Parse.Object.extend("User");
var qUser = new Parse.Query(objUser);
qUser.equalTo("username", username);
qUser.find().then(function (resultObj) {
if(resultObj.length > 0){
var userObj = resultObj[0];
userObj.set("password", password);
return userObj.save();
} else {
response.error("User does not exist");
}
}).then(function () {
response.success("Password RESET DONE SUCCESSFULLY");
}, function (error) {
response.error("Error " + error);
});
});
and call that method from your app, like this
Map<String, Object> params = new HashMap<String, Object>();
params.put("password", password);
params.put("username", username);
ParseCloud.callFunctionInBackground("resetPassword", params, new FunctionCallback<String>() {
#Override
public void done(String response, ParseException e) {
if (e == null) {
...
} else {
..
}
}
});
This way you can reset user password using username or mobile number.