How do I get the city, state and country of the user with a facebook login?
I have the following code:
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());
}