I use Facebook SDK 4.16.1 using Profile , I could get first name , last name , name and id my code is similar to this
public class LoginActivity extends Activity { String id, fname, lname, email, name, gender, locale, verified; private CallbackManager callbackManager; private AccessTokenTracker accessTokenTracker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loginactivity); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); accessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { } }; LoginButton loginButton = (LoginButton)findViewById(R.id.login_button); loginButton.setReadPermissions(Arrays.asList(Constants.FACEBOOK_PERMISSIONS)); FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { AccessToken accessToken = loginResult.getAccessToken(); Profile profile = Profile.getCurrentProfile(); FB_TOKEN=loginResult.getAccessToken().getToken(); GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted( JSONObject object, GraphResponse response) {
My constants look like
public static final String[] FACEBOOK_PERMISSIONS = new String[] { "public_profile", "user_friends", "email" };
I am trying to get email, gender, locale and if it is already verified. How do I get other information? Mine always have zero expectation for items that receive Profile
Update
I am updating my GraphRequest as follows
GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted( JSONObject object, GraphResponse response) { // Application code response.getError(); Log.e("JSON-RESULT:", object.toString()); JSONObject jsonObject = null; try { jsonObject = new JSONObject(object.toString()); email = jsonObject.getString("email"); gender = jsonObject.getString("gender"); locale = jsonObject.getString("locale"); verified = jsonObject.getString("verified"); Log.e(TAG, email + " This is the email"); } catch (JSONException e) { e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,link,birthday,first_name,last_name,email,gender,verified,locale"); request.setParameters(parameters); request.executeAsync();
In my Logcat it shows that I set the email address and others correctly, but it doesn't go inside GraphRequest when you put breakpoints , and because of this, my global variable email is still null. Even if in Log.e("JSON:", object.toString()); and Log.e(TAG, email + " This is the email"); shown that I receive and set values. I am wondering how can I get the Bundle values?