com.facebook.Session Java Examples

The following examples show how to use com.facebook.Session. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FriendPickerFragment.java    From android-skeleton-project with MIT License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #2
Source File: FacebookFragment.java    From KlyphMessenger with MIT License 6 votes vote down vote up
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
 
Example #3
Source File: FriendPickerFragment.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #4
Source File: FacebookFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
 
Example #5
Source File: StreamFragment.java    From Klyph with MIT License 6 votes vote down vote up
private void handleLikeCommentAction(final Comment comment)
{
	pendingLikeComment = false;
	pendingCommentLike = comment;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingLikeComment = true;
		requestPublishPermissions(session);
		return;
	}

	doLikeCommentAction(comment);
	pendingLikeComment = false;
}
 
Example #6
Source File: FriendPickerFragment.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + friendPickerType.getRequestPath(), null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #7
Source File: MainActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (isResumed) {
        FragmentManager manager = getSupportFragmentManager();
        int backStackSize = manager.getBackStackEntryCount();
        for (int i = 0; i < backStackSize; i++) {
            manager.popBackStack();
        }
        // check for the OPENED state instead of session.isOpened() since for the
        // OPENED_TOKEN_UPDATED state, the selection fragment should already be showing.
        if (state.equals(SessionState.OPENED)) {
            showFragment(SELECTION, false);
        } else if (state.isClosed()) {
            showFragment(SPLASH, false);
        }
    }
}
 
Example #8
Source File: EventFragment.java    From Klyph with MIT License 6 votes vote down vote up
private void handleResponseClick(int request)
{
	pendingAnnounce = false;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingAnnounce = true;
		pendingRequest = request;
		requestPublishPermissions(session);
		return;
	}

	sendRequest(request);
}
 
Example #9
Source File: FacebookFragment.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the current session.
 */
protected final void closeSession() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            currentSession.close();
        }
    }
}
 
Example #10
Source File: PlacePickerSampleActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private boolean ensureOpenSession() {
    if (Session.getActiveSession() == null ||
            !Session.getActiveSession().isOpened()) {
        Session.openActiveSession(this, true, new Session.StatusCallback() {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChanged(session, state, exception);
            }
        });
        return false;
    }
    return true;
}
 
Example #11
Source File: SessionTracker.java    From KlyphMessenger with MIT License 5 votes vote down vote up
/**
 * Set the Session object to track.
 * 
 * @param newSession the new Session object to track
 */
public void setSession(Session newSession) {
    if (newSession == null) {
        if (session != null) {
            // We're current tracking a Session. Remove the callback
            // and start tracking the active Session.
            session.removeCallback(callback);
            session = null;
            addBroadcastReceiver();
            if (getSession() != null) {
                getSession().addCallback(callback);
            }
        }
    } else {
        if (session == null) {
            // We're currently tracking the active Session, but will be
            // switching to tracking a different Session object.
            Session activeSession = Session.getActiveSession();
            if (activeSession != null) {
                activeSession.removeCallback(callback);
            }
            broadcastManager.unregisterReceiver(receiver);
        } else {
            // We're currently tracking a Session, but are now switching 
            // to a new Session, so we remove the callback from the old 
            // Session, and add it to the new one.
            session.removeCallback(callback);
        }
        session = newSession;
        session.addCallback(callback);
    }
}
 
Example #12
Source File: FacebookFragment.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets the current Session.
 * 
 * @return the current Session object.
 */
protected final Session getSession() {
    if (sessionTracker != null) {
        return sessionTracker.getSession();
    }
    return null;
}
 
Example #13
Source File: SessionTracker.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #14
Source File: SessionTracker.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
private void addBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Session.ACTION_ACTIVE_SESSION_SET);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_UNSET);
    
    // Add a broadcast receiver to listen to when the active Session
    // is set or unset, and add/remove our callback as appropriate    
    broadcastManager.registerReceiver(receiver, filter);
}
 
Example #15
Source File: FacebookFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #16
Source File: LoginButton.java    From KlyphMessenger with MIT License 5 votes vote down vote up
private void fetchUserInfo() {
    if (fetchUserInfo) {
        final Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            if (currentSession != userInfoSession) {
                Request request = Request.newMeRequest(currentSession, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser me,  Response response) {
                        if (currentSession == sessionTracker.getOpenSession()) {
                            user = me;
                            if (userInfoChangedCallback != null) {
                                userInfoChangedCallback.onUserInfoFetched(user);
                            }
                        }
                        if (response.getError() != null) {
                            handleError(response.getError().getException());
                        }
                    }
                });
                Request.executeBatchAsync(request);
                userInfoSession = currentSession;
            }
        } else {
            user = null;
            if (userInfoChangedCallback != null) {
                userInfoChangedCallback.onUserInfoFetched(user);
            }
        }
    }
}
 
Example #17
Source File: FacebookFragment.java    From android-skeleton-project with MIT License 5 votes vote down vote up
/**
 * Gets the permissions associated with the current session or null if no session 
 * has been created.
 * 
 * @return the permissions associated with the current session
 */
protected final List<String> getSessionPermissions() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getPermissions() : null;
    }
    return null;
}
 
Example #18
Source File: FacebookFragment.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the permissions associated with the current session or null if no session 
 * has been created.
 * 
 * @return the permissions associated with the current session
 */
protected final List<String> getSessionPermissions() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getPermissions() : null;
    }
    return null;
}
 
Example #19
Source File: Notifications.java    From Klyph with MIT License 5 votes vote down vote up
private void loadNotifications()
{
	pendingAnnounce = false;
	if (!hasPermissions())
	{
		pendingAnnounce = true;
		requestExtendedPermissions(Session.getActiveSession());
		return;
	}

	defineEmptyText(R.string.empty_list_no_notification);
	setIsFirstLoad(true);
	super.load();
}
 
Example #20
Source File: TitledFragmentActivity.java    From KlyphMessenger with MIT License 5 votes vote down vote up
protected void onSessionStateChange(final Session session, SessionState state, Exception exception)
{
	if (session != null && session.isOpened())
	{
		if (state.equals(SessionState.OPENED_TOKEN_UPDATED))
		{
			tokenUpdated();
		}
	}
}
 
Example #21
Source File: FriendPickerFragment.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #22
Source File: SessionTracker.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}
 
Example #23
Source File: KlyphPlacePickerFragment.java    From Klyph with MIT License 5 votes vote down vote up
private Request createRequest(Location location, int radiusInMeters, int resultsLimit, String searchText,
        Set<String> extraFields,
        Session session) {
    Request request = Request.newPlacesSearchRequest(session, location, radiusInMeters, resultsLimit, searchText,
            null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME,
            LOCATION,
            CATEGORY,
            WERE_HERE_COUNT
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #24
Source File: PreferencesActivity.java    From Klyph with MIT License 5 votes vote down vote up
private void handleSetNotifications()
{
	SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
	SharedPreferences.Editor editor = sharedPreferences.edit();

	@SuppressWarnings("deprecation") CheckBoxPreference cpref = (CheckBoxPreference) findPreference("preference_notifications");

	pendingAnnounce = false;
	final Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingAnnounce = true;
		editor.putBoolean(KlyphPreferences.PREFERENCE_NOTIFICATIONS, false);
		editor.commit();
		cpref.setChecked(false);

		AlertUtil.showAlert(this, R.string.preferences_notifications_permissions_title, R.string.preferences_notifications_permissions_message,
				R.string.ok, new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which)
					{
						requestPublishPermissions(session);
					}
				}, R.string.cancel, null);
		return;
	}

	editor.putBoolean(KlyphPreferences.PREFERENCE_NOTIFICATIONS, true);
	editor.commit();
	cpref.setChecked(true);

	startOrStopNotificationsServices();

	if (sharedPreferences.getBoolean(KlyphPreferences.PREFERENCE_NOTIFICATIONS_BIRTHDAY, false) == true)
		KlyphService.startBirthdayService();
}
 
Example #25
Source File: FacebookFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the current session as well as clearing the token cache.
 */
protected final void closeSessionAndClearTokenInformation() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            currentSession.closeAndClearTokenInformation();
        }
    }
}
 
Example #26
Source File: SessionTracker.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
/**
 * Stop tracking the Session and remove any callbacks attached
 * to those sessions.
 */
public void stopTracking() {
    if (!isTracking) {
        return;
    }
    Session session = getSession();
    if (session != null) {
        session.removeCallback(callback);
    }
    broadcastManager.unregisterReceiver(receiver);
    isTracking = false;
}
 
Example #27
Source File: FacebookShareActivity.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
private void onSessionStateChange(Session session, SessionState state, Exception exception)
{
    if(exception != null)
    {
        // Handle exception here.
        Log.v("Facebook CALLBACK", "Facebook login error " + exception);
        return;
    }
    if (state != null && state.isOpened()) {

        if (session.isPermissionGranted(PERMISSION))
        {
            if (mPendingAction)
            {
                // Session ready to make requests.
                postImageToFacebook();
                mPendingAction = false;
            }
        }
        else
        {
            // Get the permissions if we don't have them.
            session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSION));
        }
    }
    else if (state.isClosed())
    {
        // Session logged out.
        return;
    }
}
 
Example #28
Source File: FacebookFragment.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * Gets the current Session.
 * 
 * @return the current Session object.
 */
protected final Session getSession() {
    if (sessionTracker != null) {
        return sessionTracker.getSession();
    }
    return null;
}
 
Example #29
Source File: FacebookFragment.java    From KlyphMessenger with MIT License 5 votes vote down vote up
/**
 * Closes the current session as well as clearing the token cache.
 */
protected final void closeSessionAndClearTokenInformation() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            currentSession.closeAndClearTokenInformation();
        }
    }
}
 
Example #30
Source File: FacebookFragment.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * Gets the date at which the current session will expire or null if no session 
 * has been created.
 * 
 * @return the date at which the current session will expire
 */
protected final Date getExpirationDate() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        return (currentSession != null) ? currentSession.getExpirationDate() : null;
    }
    return null;
}