Java Code Examples for com.facebook.Session#openForRead()

The following examples show how to use com.facebook.Session#openForRead() . 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: FacebookFragment.java    From Klyph 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 2
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 3
Source File: FacebookFragment.java    From HypFacebook with BSD 2-Clause "Simplified" 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 4
Source File: FacebookFragment.java    From facebook-api-android-maven 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: 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 6
Source File: FacebookFragment.java    From Abelana-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 7
Source File: FacebookFragment.java    From aws-mobile-self-paced-labs-samples 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 8
Source File: FacebookFragment.java    From FacebookImageShareIntent 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 9
Source File: FacebookFragment.java    From android-skeleton-project 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 10
Source File: FacebookFragment.java    From barterli_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 11
Source File: FacebookFragment.java    From platform-friends-android with BSD 2-Clause "Simplified" 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 12
Source File: HypFacebookFrag.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
*
*
* @public
* @return	void
*/
public void authorize( ){
	trace("authorize");
	Session session = Session.getActiveSession();
       if (!session.isOpened() && !session.isClosed() ) {
           session.openForRead( new Session.OpenRequest(this).setCallback( callback ) );
       } else {
           Session.openActiveSession( getActivity( ), this , true , callback );
       }

}
 
Example 13
Source File: SessionLoginFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
    } else {
        Session.openActiveSession(getActivity(), this, true, statusCallback);
    }
}
 
Example 14
Source File: LoginUsingActivityActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
    } else {
        Session.openActiveSession(this, true, statusCallback);
    }
}
 
Example 15
Source File: LoginButton.java    From KlyphMessenger with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    Context context = getContext();
    final Session openSession = sessionTracker.getOpenSession();

    if (openSession != null) {
        // If the Session is currently open, it must mean we need to log out
        if (confirmLogout) {
            // Create a confirmation dialog
            String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
            String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
            String message;
            if (user != null && user.getName() != null) {
                message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.getName());
            } else {
                message = getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(message)
                   .setCancelable(true)
                   .setPositiveButton(logout, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                           openSession.closeAndClearTokenInformation();
                       }
                   })
                   .setNegativeButton(cancel, null);
            builder.create().show();
        } else {
            openSession.closeAndClearTokenInformation();
        }
    } else {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            sessionTracker.setSession(null);
            Session session = new Session.Builder(context).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = null;
            if (parentFragment != null) {
                openRequest = new Session.OpenRequest(parentFragment);
            } else if (context instanceof Activity) {
                openRequest = new Session.OpenRequest((Activity)context);
            }

            if (openRequest != null) {
                openRequest.setDefaultAudience(properties.defaultAudience);
                openRequest.setPermissions(properties.permissions);
                openRequest.setLoginBehavior(properties.loginBehavior);

                if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
                    currentSession.openForPublish(openRequest);
                } else {
                    currentSession.openForRead(openRequest);
                }
            }
        }
    }

    AppEventsLogger logger = AppEventsLogger.newLogger(getContext());

    Bundle parameters = new Bundle();
    parameters.putInt("logging_in", (openSession != null) ? 0 : 1);

    logger.logSdkEvent(loginLogoutEventName, null, parameters);
}
 
Example 16
Source File: LoginFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(final View v) {

    switch (v.getId()) {

        case R.id.button_facebook_login: {
            GoogleAnalyticsManager
                    .getInstance()
                    .sendEvent(new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                       .set(ParamKeys.TYPE, ParamValues.FACEBOOK));
            final Session session = Session.getActiveSession();
            if (!session.isOpened() && !session.isClosed()) {
                session.openForRead(new Session.OpenRequest(this)
                                            .setPermissions(Arrays
                                                                    .asList(AppConstants
                                                                                    .FBPERMISSIONS))
                                            .setCallback(this));
            } else {
                Session.openActiveSession(getActivity(), this, true, this);
            }
            break;
        }

        case R.id.button_google_login: {
            GoogleAnalyticsManager
                    .getInstance()
                    .sendEvent(new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                       .set(ParamKeys.TYPE, ParamValues.GOOGLE));
            ((AuthActivity) getActivity()).getPlusManager().login();
            break;
        }

        case R.id.button_submit: {
            if (isInputValid()) {
                GoogleAnalyticsManager
                        .getInstance()
                        .sendEvent(
                                new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                        .set(ParamKeys.TYPE, ParamValues.EMAIL)
                        );
                login(mEmailEditText.getText().toString(), mPasswordEditText
                        .getText().toString());
            }
            break;
        }

        case R.id.forgot_password: {
            showForgotPasswordDialog();

        }
    }
}
 
Example 17
Source File: LoginButton.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    Context context = getContext();
    final Session openSession = sessionTracker.getOpenSession();

    if (openSession != null) {
        // If the Session is currently open, it must mean we need to log out
        if (confirmLogout) {
            // Create a confirmation dialog
            String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
            String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
            String message;
            if (user != null && user.getName() != null) {
                message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.getName());
            } else {
                message = getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(message)
                   .setCancelable(true)
                   .setPositiveButton(logout, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                           openSession.closeAndClearTokenInformation();
                       }
                   })
                   .setNegativeButton(cancel, null);
            builder.create().show();
        } else {
            openSession.closeAndClearTokenInformation();
        }
    } else {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            sessionTracker.setSession(null);
            Session session = new Session.Builder(context).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = null;
            if (parentFragment != null) {
                openRequest = new Session.OpenRequest(parentFragment);
            } else if (context instanceof Activity) {
                openRequest = new Session.OpenRequest((Activity)context);
            }

            if (openRequest != null) {
                openRequest.setDefaultAudience(properties.defaultAudience);
                openRequest.setPermissions(properties.permissions);
                openRequest.setLoginBehavior(properties.loginBehavior);

                if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
                    currentSession.openForPublish(openRequest);
                } else {
                    currentSession.openForRead(openRequest);
                }
            }
        }
    }

    AppEventsLogger logger = AppEventsLogger.newLogger(getContext());

    Bundle parameters = new Bundle();
    parameters.putInt("logging_in", (openSession != null) ? 0 : 1);

    logger.logSdkEvent(loginLogoutEventName, null, parameters);
}