-1
How do I get the user’s city, state and country, with a facebook login?
I have the code below:
facebook.setReadPermissions("email", "public_profile", "user_birthday","user_location");
private void facebookLogin() {
mAuth = FirebaseAuth.getInstance();
mCallbackManager = CallbackManager.Factory.create();
facebook.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
GraphRequest graphRequest = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.d("JSON", "" + response.getJSONObject().toString());
try {
nome = object.optString("first_name");
sobrenome = object.optString("last_name");
email = object.optString("email");
aniversario = object.optString("user_birthday");
idFB = object.optString("id");
sexo = object.getString("gender");
paisLogin = object.getJSONObject("location").getString("country"); //como fazer a query?
cidade = object.getJSONObject("location").getString("city"); //como fazer a query?
SaveSharedPreferences.setIdFacebook(getContext(),idFB);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","id,first_name,last_name,email,location,gender");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
AuthCredential credential = FacebookAuthProvider.getCredential(loginResult.getAccessToken().getToken());
handleFacebookAccessToken(credential);
//handleFacebookAccessToken(loginResult.getAccessToken());
}
Thank you! In my answer I use this. My biggest doubt was how to call this new "call". But in any case it does not explain the question of the parameters, my answer puts them, without them, it is not possible to pick up the objects, but, Thank you again!
– Henrique