title: Retrieve Data From Facebook to Android
body: <p>Currently I am working with an android project where the user should be able to login to facebook with the button - Connect with Facebook, that would redirect to the next Activity with all collected data in one click. i do not know where am i making a mistake. Thanks in advance, The codes are attached below. </p>
  
  <p><strong>Test</strong> Class is the Facebook SDK initialization class, and the Result Class is <strong>Account</strong></p>
  
  <p><strong>Test Class</strong></p>
  
  <pre><code>public class Test extends AppCompatActivity {
      private static final String TAG = "SocialActivity";
      TextView txt_login_Status;
      LoginButton loginButton;
      CallbackManager callbackManager;
      ProgressDialog progressDialog;
      URL profile_pic;
      String id;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_test);
  
          FacebookSdk.sdkInitialize(getApplicationContext());
          loginButton = (LoginButton)findViewById(R.id.login_button);
          callbackManager = CallbackManager.Factory.create();
          //loginButton.setReadPermissions("email");
          loginButton.setReadPermissions("public_profile");
  
          loginButton.registerCallback(callbackManager, new FacebookCallback&lt;LoginResult&gt;() {
              @Override
              public void onSuccess(final LoginResult loginResult) {
                  progressDialog = new ProgressDialog(Test.this);
                  progressDialog.setMessage("Please Wait! Account's being processed!");
                  progressDialog.show();
                  String accessToken = loginResult.getAccessToken().getToken();
                  Log.i("accessToken",accessToken);
                  GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                              @Override
                              public void onCompleted(JSONObject object, GraphResponse response) {
                              Log.i("Test",response.toString());
                              progressDialog.hide();
                              Toast.makeText(Test.this,"Success!! Logged into Account as per given user information. ",Toast.LENGTH_LONG).show();
  
                              Bundle bFacebookData = getFacebookData(object);
                              String firstname = bFacebookData.getString( "first_name");
                              String lastname = bFacebookData.getString( "last_name");
                              String email = bFacebookData.getString( "email");
                              String profilepic = bFacebookData.getString( "profile_pic");
  
                              Intent in = new Intent(Test.this, Account.class);
                              in.putExtra("firstname", firstname);
                              in.putExtra("lastname", lastname);
                              in.putExtra("email", email);
                              in.putExtra("Image", profilepic);
                              startActivity(in);
  
                      }
                  });
  
                  Bundle parameters = new Bundle();
                  parameters.putString("fields", "id, first_name, last_name, email");
                  request.setParameters(parameters);
                  request.executeAsync();
              }
  
              @Override
              public void onCancel() {
              }
  
              @Override
              public void onError(FacebookException error) {
              }
          });
      }
  
      private Bundle getFacebookData(JSONObject object) {
  
          Bundle bundle = new Bundle();
          try{
              id = object.getString("id");
              profile_pic = new URL("https://graph.facebook.com/" + id + "/picture?width=100&amp;height=100");
              Log.i("profile_pic", profile_pic +"");
              bundle.putString("profile_pic",profile_pic.toString());
          }catch (JSONException ex){
              ex.printStackTrace();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          }
          bundle.putString("idFacebook",id);
  
          if(object.has("first_name")){
              try{
                  bundle.putString("first_name", object.getString("first_name"));
              }catch (JSONException ex){
                  ex.printStackTrace();
              }
          }
  
          if(object.has("last_name")){
              try{
                  bundle.putString("last_name", object.getString("last_name"));
              }catch (JSONException ex){
                  ex.printStackTrace();
              }
          }
  
          if(object.has("email")){
              try{
                  bundle.putString("email", object.getString("email"));
              }catch (JSONException ex){
                  ex.printStackTrace();
              }
          }
          return bundle;
      }
  
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          callbackManager.onActivityResult(requestCode, resultCode, data);
      }
  }
  </code></pre>
  
  <p><strong>Account Class</strong></p>
  
  <pre><code>public class Account extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
  
      FirebaseAuth firebaseAuth;
      Button btnSignOut;
      TextView textName, textEmail;
      FirebaseUser firebaseUser;
      ProgressDialog progressDialog;
      ImageView imageView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_profile);
  
          btnSignOut = (Button) findViewById(R.id.btnSignOut);
          textName = (TextView) findViewById(R.id.textName);
          textEmail = (TextView) findViewById(R.id.textEmail);
          imageView = (ImageView) findViewById(R.id.profileImage);
  
          String firstname = getIntent().getExtras().getString("first_name");
          String lastname = getIntent().getExtras().getString("last_name");
          String email = getIntent().getExtras().getString("email");
          String profilepic =getIntent().getExtras().getString("profile_pic");
  
          if (first_name != null &amp;&amp; last_name != null &amp;&amp; email != null &amp;&amp; profile_pic != null) {
                  textName.setText(first_name +" "+last_name);
                  textEmail.setText(email);
                  Glide.with(Account.this).load(profile_pic).into(imageView);
          } else {
              Toast.makeText(this.getApplicationContext(), "Data isnt Found!", Toast.LENGTH_LONG).show();
          }
          progressDialog = new ProgressDialog(this);
  
  
      }
  }
  </code></pre>
  
  <p>I have been following a YouTube Tutorial, Link <a href="http://Youtube%20Link" rel="nofollow noreferrer">https://www.youtube.com/watch?v=R50t9pHtWM0</a>
  Facebook Tutorial starts from 45th Minute of the video in a foriegn language.</p>
  
  <p>The message i get on my Emulator is the Toast Message from Account Activity : Toast.makeText(this.getApplicationContext(), "Data isnt Found!", Toast.LENGTH_LONG).show();</p>
  
  <p>Facebook Login Works fine, Problem is Data cant be fetched.</p>