title: Facebook graph API: Getting user Profile object null
body: <p>I am trying to get user's profile using Facebook Graph API. But sometimes I am getting Profile object value null in GraphRequest response, but there JSONObject and GraphResponse are fine. Here is the code how I am doing.</p>
  
  <p>Dependencies in build.gradle for Facebook SDK:</p>
  
  <pre><code>compile 'com.facebook.android:facebook-android-sdk:4.16.0'
  </code></pre>
  
  <p>In Activity I am doing:</p>
  
  <pre><code>@Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
          facebookCallback();
  }
  
  @Override
      public void onClick(View v) {
          switch (v.getId()) {
              case R.id.txt_login_facebook:
                  if (CommonUtils.isNetworkConnected(LoginActivity.this)) {
                      LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_birthday", "email", "user_location"));
                  } else {
                      CommonUtils.showNoInternetAlert(LoginActivity.this, null);
                  }
                  break;
              default:
                  break;
          }
      }
  
  private AccessToken accessToken;
  private CallbackManager callbackManager;
  
  private void facebookCallback() {
          callbackManager = CallbackManager.Factory.create();
          LoginManager.getInstance().registerCallback(callbackManager,
                  new FacebookCallback&lt;LoginResult&gt;() {
              @Override
              public void onSuccess(LoginResult loginResult) {
                  accessToken = loginResult.getAccessToken();
                  getUserDataThroughGraphAPI();
                  Log.i("error", "success" + "");
              }
  
              @Override
              public void onCancel() {
                  Log.e("Facebook-Login-Cancel", "Cancelled");
              }
  
              @Override
              public void onError(FacebookException exception) {
                  Log.e("Facebook-Login-onError", exception.toString());
              }
          });
      }
  
  /**
       * This method gives you data from Facebook through Graph API after successful login to Facebook.
       * Use {@link #getUserDataThroughGraphAPI()}
       *
       * @return Nothing.
       */
      private void getUserDataThroughGraphAPI() {
          try {
              GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
  
                  @Override
                  public void onCompleted(JSONObject jsonobject, GraphResponse response) {
                      Profile profile = Profile.getCurrentProfile();
                      Log.e("Facebook json", jsonobject.toString());//Getting Correctly
                      Log.e("Facebook graph", response.toString());//Getting correctly
                      Log.e("Facebook profile", profile+"");//Getting Profile Object null sometimes
                  }
              });
              Bundle parameters = new Bundle();
              parameters.putString("fields", "id,name,link,email,gender,birthday,location");
              request.setParameters(parameters);
              request.executeAsync();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      @Override
      public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          callbackManager.onActivityResult(requestCode, resultCode, data);
      }
  </code></pre>
  
  <p>Any help will be appriciated :)</p>