I am trying to login from my app using facebook login
but what I am getting in response in jsonObject
is only id and name and nothing else when i request loginButton.setReadPermissions("public_profile")
. Can anyone figure out what is the problem ? Here is my code.
public class LoginActivity extends AppCompatActivity {
LoginButton loginButton;
CallbackManager callbackManager;
String id, name, gender, ageRange;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_login);
loginButton=(LoginButton)findViewById(R.id.login_button);
callbackManager= CallbackManager.Factory.create();
loginButton.setReadPermissions("public_profile");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken=loginResult.getAccessToken();
GraphRequest graphRequest= GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
if (jsonObject!=null)
{
Log.e("JSON Object",jsonObject.toString());
Log.e("GraphResponse",graphResponse.toString());
try
{
id=jsonObject.getString("id");
name=jsonObject.getString("name");
gender=jsonObject.getString("gender");
ageRange=jsonObject.getString("age_range");
}
catch (JSONException e)
{
e.printStackTrace();
}
}
}
});
graphRequest.executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(),"Cancelled", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException e) {
Toast.makeText(getApplicationContext(),"Error while Connecting", Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode,resultCode,data);
}