I have a Http Post
try {
String response1 = null;
response1 = CustomHttpClient.executeHttpPost(
"http://giveaway.synamegames.com/appfiles/login.php",
postParameters);
String res = response1.toString();
// res = res.trim();
res = res.replaceAll("\\s+", "");
if (res.equals("2350") && checkboxv.equals("1")) {
Intent login = new Intent(this, MainMenuActivity.class);
login.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(login);
SavePreferences("lu", et_username.getText().toString());
SavePreferences("lp", et_pass.getText().toString());
SavePreferences("cbauto", "1");
} else if (res.equals("2350") && checkboxv.equals("0")) {
Intent login = new Intent(this, MainMenuActivity.class);
login.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(login);
SavePreferences("lu", "");
SavePreferences("lp", "");
SavePreferences("cbauto", "0");
} else if (res.equals("1000")) {
Toast.makeText(this, "Incorrect version. Please update.",
Toast.LENGTH_SHORT).show();
} else if (res.equals("588")) {
Toast.makeText(this, "Incorrect Password or Username.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,
"Server Error. Please try again later.",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
}
If my response is 1000, 2350, etc. it'll give the android phone a specific response. However I want my database to give android database information. In my situation I have
players register and enter in their name, email, username, and password. Upon login I want the phone to retrieve the name the user assigned when they created their account. For security reasons I can't store this information on the phone. I could have multiple HTTP Posts but that would just slow the application down. My question is...
Is there any possible way I can retrieve multiple responses and put those responses into different Strings without having to do another http post?
If you are designing the server side also, what I would do is basically returning the profile information as part of the response in JSON format. You could use JSONObject from Android to parse the JSON response from your server. So your response String for successful login would look like
{
"response" : {
"responseCode" : 2350,
"userProfile" : {
"name" : "Me",
"email" : "me#me.com"
}
}
}
And for failed response
{
"response" : {
"responseCode" : 588
}
}
This way, you don't have to make 2 http calls and would save you from another trip to the server
Related
i am trying to send some user data (its registration android page) to my server host but there is an error while trying to get json object from server side, so how can i fix this problem?
update :: i am using byethost services and i understand that there is something with cookies. so how can i solve this problem using volley library?
i have a method called onResponse() in my RegisterActivity class and its where the problem begins. in this method i wrote this line which always throws exception about not converting string to json object which i think there is nothing to do with my java codes, the reason it cant convert string to json i guess is that its not a valid json object. but i dont know why it is not valid.
here is my register.php file
https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/register.txt
https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/update_user_info.txt
https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/android_login_connect.txt
https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/android_login_config.txt
by the way i i just followed a tutorial i do not know so much about php.
here is the method in my RegisterActivity class where the exception triggers.
#Override
public void onResponse(String response) {
Toast.makeText(RegisterActivity.this, response,
Toast.LENGTH_LONG).show();
Log.d(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
String user =
jObj.getJSONObject("user").getString("name");
Toast.makeText(getApplicationContext(), "Hi " + user +
", You are successfully Added!",
Toast.LENGTH_SHORT).show();
// Launch login activity
Intent intent = new Intent(
RegisterActivity.this,
LoginActivity.class);
startActivity(intent);
finish();
} else {
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
i expect to have a valid json object to pass the user data to my server but what i already have is some invalid json which throws exceptions.
well if anyone have followed the tutorials for register and login page and it does not work here are some reasons.
1) there is a problem with your php file which mostly its this one.
2) if there are problem with converting string to json object, print the string and see if its a valid json.
3)if everything is fine with these stuff, probably you should check the database and see if everything can fit with the php and user data and etc.
my problem was neither of those, as it turns out my server host have something to do with cookies (byethost) and you should add some headers for solving the problem here is a good link
How to set custom header in Volley Request
but i just solved my problem by using another server host (000host) and it works just fine. by the way if you are trying to use wamp and it doesn't work too, just use free 000host. it's been three days i was stuck on this thing. good luck
Do you guys use the Google Cloud Platform, specifically the APP ENGINE ENDPOINTs for professional/production purposes? Asking because I am not comfortable with response time. It´s taking too long to perform simple http POST requests like registering an users with only e-mail and password (saving in a DATASTORE). In this URL you will find the register form, let me know what you guys thing about the response time, is it acceptable?
https://filiperebollo1986.appspot.com/register.html
My Java code is quite simple. Only instantiate an user object with email and password which does´t have any special encrypting algorithm. Naturally for the registering purpose I need to check if the user already exists and after that save the object in the DATASTORE. I can ensure that the problem is not in my front-end apps because takes too long in the iOS e Android apps too.
POST:
https://filiperebollo1986.appspot.com/_ah/api/igardenendpoints/v12/saveProfile.
{
"userEmail": "response_time",
"password": "123"
}
Response:
200
Show headers
{
"messageText": "User successfully created!",
"messageNumer": 0,
"kind": "igardenendpoints#resourcesItem",
"etag": "\"9e-bXvBAIkMzDxg9PvVcUBMIXB0/_RzWmXdehTtOTMg1Y7MhIvXy5-k\""
}
public Message saveProfile(ProfileForm profileForm) {
Message message;
String userEmail = profileForm.getUserEmail();
String password = profileForm.getPassword();
String displayName = profileForm.getDisplayName();
Profile profile = ofy().load().key(Key.create(Profile.class, profileForm.getUserEmail())).now();
if (profile == null) {
if (displayName == "") {
displayName = extractDefaultDisplayNameFromEmail(profileForm.getUserEmail());
}
profile = new Profile(userEmail, password, displayName);
message = new Message("User successfully created!", 0);
} else {
message = new Message("User already exists!", 1);
}
ofy().save().entity(profile).now();
return message;
}
I am new to parse, trying to reset a password by:
user.requestPasswordResetInBackground(password.getText().toString(), new RequestPasswordResetCallback() {
#Override
public void done(com.parse.ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(), "Password rest email has been sent to your inbox", Toast.LENGTH_LONG).show();
}else if(e.getCode()== com.parse.ParseException.INVALID_EMAIL_ADDRESS){
Toast.makeText(getApplicationContext(),"Email not found",Toast.LENGTH_LONG).show();
}
}
});
Everything is fine an email will be sent to the inbox, by how I can tell Parse to validate the password at least 8 characters (it's taking everything even 1234)
Thank you
I think you can write a cloud code, so before _User object is updated, check user.get("password").length.
Something Like this:
PF.Cloud.beforeSave("_User", function(request, response) {
//Prototype linking
var user = request.object;
if (user.get("password").length >= 8) {
response.success();
} else {
response.error("Password too short");
}
});
For more information, please visit the reference: Cloud Code
So I'm building a signup procedure that needs the user to verify their phone number by receiving a code by sms. I'm using Parse as the backend system and I'm using Twilio service which comes included in Parse to take care of the sms function. I have been successful in sending the verification code to user's number.
This is my parse cloud code:
var client = require('twilio')('ACb3....', '2b3....');
//Send an SMS text message
Parse.Cloud.define("sendVerificationCode", function(request, response) {
var verificationCode = Math.floor(Math.random()*999999);
client.sendSms({
From: "+61437877758",
To: request.params.phoneNumber,
Body: "Your verification code is " + verificationCode + "."
}, function(err, responseData) {
if (err) {
response.error(err);
} else {
response.success("Success");
}
});
});
This is the code from the app:
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("phoneNumber", userNumber);
ParseCloud.callFunctionInBackground("sendVerificationCode", params, new FunctionCallback<String>() {
public void done(String result, ParseException e) {
if (e == null) {
Log.d("Parse", result);
Intent i = new Intent(SignupActivity.this, PhoneVerificationActivity.class);
startActivity(i);
} else {
Toast.makeText(SignupActivity.this, "there was a problem with connection", Toast.LENGTH_LONG).show();
}
}
});
Now I would like to know how can I send that verification code back to my android app from Parse Cloud after success, so tat I can check the verification code against the code user puts in the EditText
if (err) {
response.error(err);
} else {
*//So the code for sending the verification code back goes here:*
response.success("Success");
}
Do I need to use Json and Rest API?, how can I call and grab this verification code from the app?.
I would really appreciate your help. Thanks.
One way would be to return it in response.success...
response.success({ status: "success", verificationCode: ... });
Another way, a better way, is to not trust the client with this. Store a record of it on an object on the server... When the user enters the validation code, call back into another function to check if it is valid. An example of this type of system can be seen in this old out-dated GitHub login example: https://github.com/ParsePlatform/CloudCodeOAuthGitHubTutorial/blob/master/cloud/main.js#L116
Hy guys, i am try to get the mutual friends between the logged user and other users by belwo method but i got empty data node although the error is null. any help regarding this issue.
private void getMutualFriends() {
Bundle params = new Bundle();
params.putString("fields", "id,name,picture");
getFriendsIds().put("100005132166273", "");
RequestBatch requestBatch = new RequestBatch();
for (final String friendId : getFriendsIds().keySet()) {
requestBatch.add(new Request(Session.getActiveSession(), "/me/mutualfriends/" + friendId, params, HttpMethod.GET, new Request.Callback() {
public void onCompleted(Response response) {
Log.i("Result: " , response.toString());
GraphObject graphObject = response.getGraphObject();
if (graphObject != null) {
if (graphObject.getProperty("id") != null) {
}
}
}
}));
}
requestBatch.executeAsync();
}
I always got this response {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}.
I replace the request creation by this also "new Request(Session.getActiveSession(), "me/mutualfriends/" + friendId, null, HttpMethod.GET, new Request.Callback().......
And got the same response.
I will execute the method about 1000 time so i used Facebook request batch if you know better method lets me know please.
I know I might be a bit naive here, but maybe the users you're checking have no mutual friends?
Are you familiar with the "Graph API" explorer? It's very useful:
https://developers.facebook.com/tools/explorer/
Try pasting your url (remember to replace 'friendsId' with the user you're checking against) and see what you get.