/** Get the current user profile info */ private void makeMeRequest() { final Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { Request request = Request.newMeRequest( session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { isMakeMeRequestStarted = false; dismissProgressDialog(); if (session == Session.getActiveSession() && user != null) { mUser = user; updateUI(); } if (response != null && response.getError() != null) { Utils.handleError( getActivity(), response.getError(), Utils.getProfileReadPermission()); } } }); request.executeAsync(); } }
@Override public void onHiddenChanged(boolean hidden) { super.onHiddenChanged(hidden); final Session session = Session.getActiveSession(); if (mUser == null && !hidden && session != null && session.isOpened()) { if (!isMakeMeRequestStarted) { makeMeRequest(); isMakeMeRequestStarted = true; } if (!isStatusesRequestStarted) { startStatusesRequest(); isStatusesRequestStarted = true; } showProgressDialog(); } }
/** Get the user's status */ private void startStatusesRequest() { Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { new Request( session, "/me/statuses", null, HttpMethod.GET, new Request.Callback() { public void onCompleted(Response response) { isStatusesRequestStarted = false; dismissProgressDialog(); handleStatusResponse(response); } }) .executeAsync(); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); }
public void loginWithFacebook() { // start Facebook Login Session currentSession = Session.getActiveSession(); if (currentSession == null || currentSession.getState().isClosed()) { Session session = new Session.Builder(this).build(); Session.setActiveSession(session); currentSession = session; } // Ask for username and password Session.OpenRequest op = new Session.OpenRequest(this); op.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK); op.setCallback(null); List<String> permissions = new ArrayList<String>(); permissions.add("email"); permissions.add("user_status"); permissions.add("friends_status"); permissions.add("read_stream"); op.setPermissions(permissions); Session session = new Session.Builder(LoginActivity.this).build(); Session.setActiveSession(session); session.addCallback( new Session.StatusCallback() { // callback when session changes state @Override public void call(Session session, SessionState state, Exception exception) { final String accessToken = session.getAccessToken(); if (session.isOpened()) { Request.executeMeRequestAsync( session, new Request.GraphUserCallback() { public void onCompleted(GraphUser user, Response response) { if (user == null) { DialogHelper.showRetryDialog( LoginActivity.this, getString(R.string.could_not_connect_fb_account), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { loginWithFacebook(); } }, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { finish(); } }); } else { final String name = user.getName(); final String email = (String) user.getProperty("email"); Toast.makeText(LoginActivity.this, name + " " + email, Toast.LENGTH_LONG) .show(); UserHelper.setCurrentUser(user, accessToken); Intent i = new Intent(LoginActivity.this, RevibeActivity.class); startActivity(i); finish(); } } }); } } }); session.openForRead(op); }