Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get Facebook photo, full name, gender using Facebook SDK android
    text
    copied!<p>I am working on an Android application in which any Android user who is logging to Facebook using our Application, I need to extract his photo, his gender, his full name from the Facebook. I am using Facebook SDK for this.</p> <p>With the help of Facebook SDK, I am able to login into Facebook but I am not sure how to extract his photo,gender and full name from the facebook?</p> <p>Below is the code I am using to login into Facebook. I followed this <a href="https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/#prerequisities">tutorial</a></p> <pre><code>public class SessionLoginFragment extends Fragment { private static final String URL_PREFIX_FRIENDS = "https://graph.facebook.com/me/friends?access_token="; private TextView textInstructionsOrLink; private Button buttonLoginLogout; private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment, container, false); buttonLoginLogout = (Button) view.findViewById(R.id.buttonLoginLogout); textInstructionsOrLink = (TextView) view.findViewById(R.id.instructionsOrLink); Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return view; } @Override public void onStart() { super.onStart(); Session.getActiveSession().addCallback(statusCallback); } @Override public void onStop() { super.onStop(); Session.getActiveSession().removeCallback(statusCallback); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { Log.d("Hello", URL_PREFIX_FRIENDS + session.getAccessToken()); Intent i = new Intent(getActivity(), ThesisProjectAndroid.class); startActivity(i); } else { Log.d("Hello", "Login Failed"); textInstructionsOrLink.setText(R.string.instructions); buttonLoginLogout.setText(R.string.login); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } private void onClickLogin() { Session session = Session.getActiveSession(); if (!session.isOpened() &amp;&amp; !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private void onClickLogout() { Session session = Session.getActiveSession(); if (!session.isClosed()) { session.closeAndClearTokenInformation(); } } private class SessionStatusCallback implements Session.StatusCallback { @Override public void call(Session session, SessionState state, Exception exception) { updateView(); } } } </code></pre> <p>Can anyone tell me where I need to make changes in the above class to get all the three information I needed. As far as I know If I am able to get facebook unique id for that person, I can get all the information I guess. Any thoughts?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload