Search in sources :

Example 21 with Session

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

the class SessionTracker method setSession.

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

Example 22 with Session

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

the class ConnectPlugin method initialize.

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    //Initialize UiLifecycleHelper
    uiHelper = new UiLifecycleHelper(cordova.getActivity(), null);
    // Init logger
    logger = AppEventsLogger.newLogger(cordova.getActivity());
    int appResId = cordova.getActivity().getResources().getIdentifier("fb_app_id", "string", cordova.getActivity().getPackageName());
    applicationId = cordova.getActivity().getString(appResId);
    // Set up the activity result callback to this class
    cordova.setActivityResultCallback(this);
    // Open a session if we have one cached
    Session session = new Session.Builder(cordova.getActivity()).setApplicationId(applicationId).build();
    if (session.getState() == SessionState.CREATED_TOKEN_LOADED) {
        Session.setActiveSession(session);
        // - Create the request
        Session.OpenRequest openRequest = new Session.OpenRequest(cordova.getActivity());
        // - Set the status change call back
        openRequest.setCallback(new Session.StatusCallback() {

            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChange(state, exception);
            }
        });
        session.openForRead(openRequest);
    }
    // If we have a valid open session, get user's info
    if (checkActiveSession(session)) {
        // Call this method to initialize the session state info
        onSessionStateChange(session.getState(), null);
    }
    super.initialize(cordova, webView);
}
Also used : SessionState(com.facebook.SessionState) UiLifecycleHelper(com.facebook.UiLifecycleHelper) FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) JSONException(org.json.JSONException) FacebookServiceException(com.facebook.FacebookServiceException) FacebookException(com.facebook.FacebookException) FacebookDialogException(com.facebook.FacebookDialogException) FacebookAuthorizationException(com.facebook.FacebookAuthorizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Session(com.facebook.Session)

Example 23 with Session

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

the class ConnectPlugin method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    Log.d(TAG, "activity result in plugin: requestCode(" + requestCode + "), resultCode(" + resultCode + ")");
    if (trackingPendingCall) {
        uiHelper.onActivityResult(requestCode, resultCode, intent, new FacebookDialog.Callback() {

            @Override
            public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
                Log.e("Activity", String.format("Error: %s", error.toString()));
                handleError(error, showDialogContext);
            }

            @Override
            public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
                Log.i("Activity", "Success!");
                handleSuccess(data);
            }
        });
    } else {
        Session session = Session.getActiveSession();
        if (session != null && loginContext != null) {
            session.onActivityResult(cordova.getActivity(), requestCode, resultCode, intent);
        }
    }
    trackingPendingCall = false;
}
Also used : FacebookDialog(com.facebook.widget.FacebookDialog) Bundle(android.os.Bundle) FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) JSONException(org.json.JSONException) FacebookServiceException(com.facebook.FacebookServiceException) FacebookException(com.facebook.FacebookException) FacebookDialogException(com.facebook.FacebookDialogException) FacebookAuthorizationException(com.facebook.FacebookAuthorizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Session(com.facebook.Session)

Example 24 with Session

use of com.facebook.Session in project Klyph by jonathangerbaud.

the class StreamFragment method handleReplyAction.

private void handleReplyAction(final Comment comment) {
    pendingReplyComment = false;
    pendingCommentReply = comment;
    Session session = Session.getActiveSession();
    List<String> permissions = session.getPermissions();
    if (!permissions.containsAll(PERMISSIONS)) {
        pendingReplyComment = true;
        requestPublishPermissions(session);
        return;
    }
    replyToComment(comment);
}
Also used : KlyphSession(com.abewy.android.apps.klyph.core.KlyphSession) Session(com.facebook.Session)

Example 25 with Session

use of com.facebook.Session in project Klyph by jonathangerbaud.

the class SessionTracker method setSession.

/**
 * 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);
    }
}
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