com.facebook.Session.StatusCallback Java Examples

The following examples show how to use com.facebook.Session.StatusCallback. 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: Facebook.java    From platform-friends-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #2
Source File: Facebook.java    From Klyph with MIT License 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #3
Source File: Facebook.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #4
Source File: Facebook.java    From android-skeleton-project with MIT License 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #5
Source File: Facebook.java    From FacebookImageShareIntent with MIT License 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #6
Source File: Facebook.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(permissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #7
Source File: Facebook.java    From Abelana-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #8
Source File: Facebook.java    From KlyphMessenger with MIT License 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #9
Source File: Facebook.java    From facebook-api-android-maven with Apache License 2.0 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(pendingAuthorizationPermissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #10
Source File: Facebook.java    From HypFacebook with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(permissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}
 
Example #11
Source File: Facebook.java    From FacebookNewsfeedSample-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Full authorize method.
 * 
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 * 
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 * 
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 * 
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 * 
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 * 
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 * 
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 * 
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 * 
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *            app/Activity.html for more information.
 * @param behavior
 *            The {@link SessionLoginBehavior SessionLoginBehavior} that
 *            specifies what behaviors should be attempted during
 *            authorization.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
private void authorize(Activity activity, String[] permissions, int activityCode,
                      SessionLoginBehavior behavior, final DialogListener listener) {
    checkUserSession("authorize");
    pendingOpeningSession = new Session.Builder(activity).
            setApplicationId(mAppId).
            setTokenCachingStrategy(getTokenCache()).
            build();
    pendingAuthorizationActivity = activity;
    pendingAuthorizationPermissions = (permissions != null) ? permissions : new String[0];

    StatusCallback callback = new StatusCallback() {
        @Override
        public void call(Session callbackSession, SessionState state, Exception exception) {
            // Invoke user-callback.
            onSessionCallback(callbackSession, state, exception, listener);
        }
    };

    Session.OpenRequest openRequest = new Session.OpenRequest(activity).
            setCallback(callback).
            setLoginBehavior(behavior).
            setRequestCode(activityCode).
            setPermissions(Arrays.asList(permissions));
    openSession(pendingOpeningSession, openRequest, pendingAuthorizationPermissions.length > 0);
}