Search in sources :

Example 1 with Session

use of com.facebook.Session in project openkit-android by OpenKit.

the class FacebookFragment method openSession.

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);
            }
        }
    }
}
Also used : Session(com.facebook.Session)

Example 2 with Session

use of com.facebook.Session in project openkit-android by OpenKit.

the class SessionTracker method stopTracking.

/**
     * 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;
}
Also used : Session(com.facebook.Session)

Example 3 with Session

use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.

the class ConnectPlugin method onSessionStateChange.

/*
     * Handles session state changes
     */
private void onSessionStateChange(SessionState state, Exception exception) {
    Log.d(TAG, "onSessionStateChange:" + state.toString());
    if (exception != null && exception instanceof FacebookOperationCanceledException) {
        // only handle FacebookOperationCanceledException to support
        // SDK recovery behavior triggered by getUserInfo
        Log.e(TAG, "exception:" + exception.toString());
        handleError(exception, loginContext);
    } else {
        final Session session = Session.getActiveSession();
        // Check if the session is open
        if (state.isOpened()) {
            if (loginContext != null) {
                // Get user info
                getUserInfo(session, new Request.GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        // Create a new result with response data
                        if (loginContext != null) {
                            if (response.getError() != null) {
                                loginContext.error(getFacebookRequestErrorResponse(response.getError()));
                            } else {
                                GraphObject graphObject = response.getGraphObject();
                                Log.d(TAG, "returning login object " + graphObject.getInnerJSONObject().toString());
                                userID = user.getId();
                                loginContext.success(getResponse());
                                loginContext = null;
                            }
                        } else {
                            // Just update the userID in case we force quit the application before
                            userID = user.getId();
                        }
                    }
                });
            } else if (graphContext != null) {
                // Make the graph call
                makeGraphCall();
            }
        } else if (state == SessionState.CLOSED_LOGIN_FAILED && loginContext != null) {
            handleError(new FacebookAuthorizationException("Session was closed and was not closed normally"), loginContext);
        }
    }
}
Also used : Response(com.facebook.Response) FacebookAuthorizationException(com.facebook.FacebookAuthorizationException) FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) GraphUser(com.facebook.model.GraphUser) GraphUserCallback(com.facebook.Request.GraphUserCallback) Request(com.facebook.Request) GraphObject(com.facebook.model.GraphObject) Session(com.facebook.Session)

Example 4 with Session

use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.

the class FacebookFragment method openSession.

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);
            }
        }
    }
}
Also used : Session(com.facebook.Session)

Example 5 with Session

use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.

the class SessionTracker method stopTracking.

/**
     * 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;
}
Also used : Session(com.facebook.Session)

Aggregations

Session (com.facebook.Session)47 KlyphSession (com.abewy.android.apps.klyph.core.KlyphSession)16 Response (com.facebook.Response)6 FacebookException (com.facebook.FacebookException)5 Request (com.facebook.Request)5 GraphUser (com.facebook.model.GraphUser)5 FacebookAuthorizationException (com.facebook.FacebookAuthorizationException)4 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)4 SessionState (com.facebook.SessionState)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 JSONException (org.json.JSONException)4 Bundle (android.os.Bundle)3 SpannableString (android.text.SpannableString)3 FacebookDialogException (com.facebook.FacebookDialogException)3 FacebookServiceException (com.facebook.FacebookServiceException)3 GraphUserCallback (com.facebook.Request.GraphUserCallback)3 FacebookRequestError (com.facebook.FacebookRequestError)2 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)2 SessionTracker (com.facebook.internal.SessionTracker)2 GraphObject (com.facebook.model.GraphObject)2