-
-
Save osw4l/06db36b382db9b9c42959465f63c0f07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void getOrCreateUser(final ParseUser parseUser, final String email, final ProgressDialog dialog){ | |
String URL = "https://example.co/api/accounts?email="+ email +"&action=get_or_create"; | |
JsonArrayRequest req = new JsonArrayRequest(URL, new com.android.volley.Response.Listener<JSONArray>() { | |
@Override | |
public void onResponse(JSONArray jsonArray) { | |
try { | |
JSONObject apiUser = jsonArray.getJSONObject(0); | |
parseUser.put("email", email); | |
parseUser.put("api_token", apiUser.getString("token")); | |
parseUser.put("api_id", apiUser.getInt("id")); | |
parseUser.put("android", 1); | |
parseUser.saveInBackground(new SaveCallback() { | |
@Override | |
public void done(ParseException e) { | |
dialog.dismiss(); | |
navigateToMainActivity(); | |
executePostLogin(); | |
} | |
}); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
}, null){ | |
@Override | |
public Map<String, String> getHeaders() throws AuthFailureError { | |
HashMap<String, String> headers = new HashMap<String, String>(); | |
headers.put("Authorization", "Token 8ca05d96c4dbeb18caaaaaaa9ab92c3"); | |
return headers; | |
} | |
}; | |
AquehorajuegaApplication.getInstance().addToRequestQueue(req); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment