private void fetchUserInfo() { final Session currentSession = getSession(); if (currentSession != null && currentSession.isOpened()) { if (currentSession != userInfoSession) { Request request = Request.newMeRequest(currentSession, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser me, Response response) { if (currentSession == getSession()) { user = me; updateUI(); } if (response.getError() != null) { loginButton.handleError(response.getError().getException()); } } }); Bundle parameters = new Bundle(); parameters.putString(FIELDS, REQUEST_FIELDS); request.setParameters(parameters); Request.executeBatchAsync(request); userInfoSession = currentSession; } } else { user = null; } }
@Override PickerFragmentAdapter<GraphUser> createAdapter() { PickerFragmentAdapter<GraphUser> adapter = new PickerFragmentAdapter<GraphUser>( this.getActivity()) { @Override protected int getGraphObjectRowLayoutId(GraphUser graphObject) { return R.layout.com_facebook_picker_list_row; } @Override protected int getDefaultPicture() { return R.drawable.com_facebook_profile_default_icon; } }; adapter.setShowCheckbox(true); adapter.setShowPicture(getShowPictures()); adapter.setSortFields(Arrays.asList(new String[]{NAME})); adapter.setGroupByField(NAME); return adapter; }
@Override protected void onLoadFinished(GraphObjectPagingLoader<GraphUser> loader, SimpleGraphObjectCursor<GraphUser> data) { super.onLoadFinished(loader, data); // We could be called in this state if we are clearing data or if we are being re-attached // in the middle of a query. if (data == null || loader.isLoading()) { return; } if (data.areMoreObjectsAvailable()) { // We got results, but more are available. followNextLink(); } else { // We finished loading results. hideActivityCircle(); // If this was from the cache, schedule a delayed refresh query (unless we got no results // at all, in which case refresh immediately. if (data.isFromCache()) { loader.refreshOriginalRequest(data.getCount() == 0 ? CACHED_RESULT_REFRESH_DELAY : 0); } } }
public static Promise<List<GraphUser>, BError, Void> getUserFriendList(){ final Deferred<List<GraphUser>, BError, Void> deferred = new DeferredObject<>(); if (!Session.getActiveSession().getState().isOpened()) { return deferred.reject(new BError(BError.Code.SESSION_CLOSED)); } Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() { @Override public void onCompleted(List<GraphUser> users, Response response) { deferred.resolve(users); } }); req.executeAsync(); return deferred.promise(); }
private void startLogin(GraphUser user, Session session) { try { loginMode = true; Fragment fragment = new FragmentSignIn(); Bundle args = new Bundle(); args.putInt(FragmentSignIn.LOGIN_MODE_ARG, LoginActivity.Mode.FACEBOOK.ordinal()); args.putString(FragmentSignIn.LOGIN_PASSWORD_OR_TOKEN_ARG, session.getAccessToken()); args.putString(FragmentSignIn.LOGIN_USERNAME_ARG, (String) user.getProperty("email")); fragment.setArguments(args); getChildFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, "tag").setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit(); Analytics.SocialTimeline.login(); } catch (Exception e) { e.printStackTrace(); } }
public void requestUserData( Session session ) { // Request user data and show the results Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { User currentUser = new User(); currentUser.setUserId(user.getId()); currentUser.setUserName(user.getUsername()); currentUser.setFirstName(user.getFirstName()); currentUser.setLastName(user.getLastName()); currentUser.setDisplayName(user.getName()); currentUser.setMail((String) user.getProperty("email")); currentUser.setProviderDisplayName("Facebook"); currentUser.setProvider(PROVIDER_NAME); FbLoginDelegate.this.mUserHelper.setCurrentUser(currentUser); if ( mUserSessionCallback != null) { mUserSessionCallback.onLogin(); } } } }).executeAsync(); }
@Override public void call(Session session, SessionState state, Exception exception) { if (session.isOpened()) { setFacebookSession(session); // make request to the /me API Request.newMeRequest(session, new Request.GraphUserCallback() { // callback after Graph API response with user object @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { Toast.makeText(LoginActivity.this, "Hello " + user.getName(), Toast.LENGTH_LONG) .show(); } } }).executeAsync(); } }
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PICK_FRIENDS_ACTIVITY: /* Session session = Session.getActiveSession(); if(session != null) { session.close(); } */ Collection<GraphUser> selection = FriendPickerData.getSelectedUsers(); if (selection != null && selection.size() > 0) { finish(); } } }
@Override protected void onStart() { super.onStart(); try { List<GraphUser> selectedUsers = FriendPickerData.getSelectedUsers(); if (selectedUsers != null) { FriendPickerData.setSelectedUsers(null); // friendPickerFragment.setSelection(selectedUsers); } // Load data, unless a query has already taken place. friendPickerFragment.loadData(false); } catch (Exception ex) { onError(ex); } }
private void getSelectedFriendData() { //check if user's friends available with this app, If not than share / invite and return if(!UserHome.hasAppFriends){ shareOrInvite(); return; } Collection<GraphUser> selection = FriendPickerData.getSelectedUsers(); if (selection != null && selection.size() > 0) { GraphUser friend = selection.iterator().next(); String friendId = friend.getId(); String friendName = friend.getName(); Intent intent = new Intent(this, OutgoingCallActivity.class); intent.putExtra(EXTRA_REMOTE_USER_ID, friendId); intent.putExtra(EXTRA_REMOTE_USER_NAME, friendName); startActivityForResult(intent, OUTGOING_CALL_ACTIVITY); } else { finish(); } }
private void onFriendPickerDone(FriendPickerFragment fragment) { FragmentManager fm = getSupportFragmentManager(); fm.popBackStack(); String results = ""; List<GraphUser> selection = fragment.getSelection(); tags = selection; if (selection != null && selection.size() > 0) { ArrayList<String> names = new ArrayList<String>(); for (GraphUser user : selection) { names.add(user.getName()); } results = TextUtils.join(", ", names); } else { results = getString(R.string.no_friends_selected); } showAlert(getString(R.string.you_picked), results); }
@Override protected void onSessionStateChange(Session session, SessionState state, Exception exception){ final TextView txtUserDetails = (TextView) mCurrentView.findViewById(R.id.mapViewLoggedInUser); if (session != null && session.isOpened()) { Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { txtUserDetails.setText("Logged in as " + user.getName()); System.out.println("onSessionStateChange: LoadNotes: session is open. username:"+user.getName()); } } }); Request.executeBatchAsync(request); } else if (session.isClosed()) { txtUserDetails.setText(""); System.out.println("onSessionStateChange: LoadNotes: session was closed."); } }
private void onSessionStateChangeP(Session session, SessionState state, Exception exception) { if (session != null && session.isOpened()) { Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { LoggedInUser = user; } } }); Request.executeBatchAsync(request); } else if (session.isClosed()) { LoggedInUser = null; } onSessionStateChange(session, state, exception); }
protected void onSessionStateChange(Session session, SessionState state, Exception exception){ if (session != null && session.isOpened()) { logAndShowOnScreen("\nLogged in. Getting user details."); Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { System.out.println("onSessionStateChange: LoadNotes: session is open. username:"+user.getName()); loadNotes(getActivity(), user.getId()); } } }); Request.executeBatchAsync(request); } else { logAndShowOnScreen("\nUser not already logged in."); System.out.println("onSessionStateChange: LoadNotes: session was closed."); loadNotes(getActivity(), getLoggedInUsername()); } }
private void populateLoggedInUser() { final TextView txtUserDetails = (TextView) this.getActivity().findViewById(R.id.userDetails); final Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // If the session is open, make an API call to get user data // and define a new callback to handle the response Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { // If the response is successful if (session == Session.getActiveSession()) { if (user != null) { String user_ID = user.getId();//user id String profileName = user.getName();//user's profile name txtUserDetails.setText(user.getName()); } } } }); Request.executeBatchAsync(request); } else if (session == null || session.isClosed()) { } }