Java 类com.facebook.AccessTokenSource 实例源码

项目:kognitivo    文件:LoginMethodHandler.java   
static AccessToken createAccessTokenFromNativeLogin(
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) {
    Date expires = Utility.getBundleLongAsDate(
            bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
    ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
    String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String userId = bundle.getString(NativeProtocol.EXTRA_USER_ID);

    return new AccessToken(
            token,
            applicationId,
            userId,
            permissions,
            null,
            source,
            expires,
            new Date());
}
项目:YalantisInternship    文件:RealmManager.java   
@Override
public AccessToken getToken() {

    TokenRealm tokenRealm = mDatabaseRealm.getToken();

    if (tokenRealm == null) {
        return null;
    }

    return new AccessToken(tokenRealm.getToken(),
            tokenRealm.getAppId(),
            tokenRealm.getUserId(),
            tokenRealm.getPermissionsList(),
            tokenRealm.getDeclinedPermissionsList(),
            AccessTokenSource.valueOf(tokenRealm.getTokenSource()),
            new Date(tokenRealm.getExpirationDate()),
            new Date(tokenRealm.getLastRefreshTime()));
}
项目:Move-Alarm_ORCA    文件:LoginMethodHandler.java   
static AccessToken createAccessTokenFromNativeLogin(
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) {
    Date expires = Utility.getBundleLongAsDate(
            bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
    ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
    String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String userId = bundle.getString(NativeProtocol.EXTRA_USER_ID);

    return new AccessToken(
            token,
            applicationId,
            userId,
            permissions,
            null,
            source,
            expires,
            new Date());
}
项目:SocioBlood    文件:LoginMethodHandler.java   
static AccessToken createAccessTokenFromNativeLogin(
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) {
    Date expires = Utility.getBundleLongAsDate(
            bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
    ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
    String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String userId = bundle.getString(NativeProtocol.EXTRA_USER_ID);

    return new AccessToken(
            token,
            applicationId,
            userId,
            permissions,
            null,
            source,
            expires,
            new Date());
}
项目:yako    文件:MainActivity.java   
/**
 * Opens Facebook session if exists.
 * 
 * @param context
 */
public static void openFbSession(Context context) {
  if (fbToken == null) {
    fbToken = StoreHandler.getFacebookAccessToken(context);
    Date expirationDate = StoreHandler.getFacebookAccessTokenExpirationDate(context);
    // Log.d( "rgai", "expiration date readed -> " + expirationDate.toString());
    if (fbToken != null) {
      Session.openActiveSessionWithAccessToken(context,
              AccessToken.createFromExistingAccessToken(fbToken, expirationDate, new Date(2013, 1, 1),
                      AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, Settings.getFacebookPermissions()),
              new Session.StatusCallback() {
                @Override
                public void call(Session sn, SessionState ss, Exception excptn) {}
              }
      );
    }
  }
}
项目:kognitivo    文件:LoginMethodHandler.java   
public static AccessToken createAccessTokenFromWebBundle(
        Collection<String> requestedPermissions,
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) throws FacebookException {
    Date expires = Utility.getBundleLongAsDate(bundle, AccessToken.EXPIRES_IN_KEY, new Date());
    String token = bundle.getString(AccessToken.ACCESS_TOKEN_KEY);

    // With Login v4, we now get back the actual permissions granted, so update the permissions
    // to be the real thing
    String grantedPermissions = bundle.getString("granted_scopes");
    if (!Utility.isNullOrEmpty(grantedPermissions)) {
        requestedPermissions = new ArrayList<String>(
                Arrays.asList(grantedPermissions.split(",")));
    }
    String deniedPermissions = bundle.getString("denied_scopes");
    List<String> declinedPermissions = null;
    if (!Utility.isNullOrEmpty(deniedPermissions)) {
        declinedPermissions = new ArrayList<String>(
                Arrays.asList(deniedPermissions.split(",")));
    }

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String signed_request = bundle.getString("signed_request");
    String userId = getUserIDFromSignedRequest(signed_request);

    return new AccessToken(
            token,
            applicationId,
            userId,
            requestedPermissions,
            declinedPermissions,
            source,
            expires,
            new Date());
}
项目:kognitivo    文件:KatanaProxyLoginMethodHandler.java   
private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
    Bundle extras = data.getExtras();
    String error = getError(extras);
    String errorCode = extras.getString("error_code");
    String errorMessage = getErrorMessage(extras);

    String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    if (error == null && errorCode == null && errorMessage == null) {
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(),
                    extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB,
                    request.getApplicationId());
            return LoginClient.Result.createTokenResult(request, token);
        } catch (FacebookException ex) {
            return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
        }
    } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
        return null;
    } else if (ServerProtocol.errorsUserCanceled.contains(error)) {
        return LoginClient.Result.createCancelResult(request, null);
    } else {
        return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
    }
}
项目:kognitivo    文件:GetTokenLoginMethodHandler.java   
void onComplete(final LoginClient.Request request, final Bundle result) {
    AccessToken token = createAccessTokenFromNativeLogin(
            result,
            AccessTokenSource.FACEBOOK_APPLICATION_SERVICE,
            request.getApplicationId());
    LoginClient.Result outcome =
            LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
    loginClient.completeAndValidate(outcome);
}
项目:Move-Alarm_ORCA    文件:LoginMethodHandler.java   
public static AccessToken createAccessTokenFromWebBundle(
        Collection<String> requestedPermissions,
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) throws FacebookException {
    Date expires = Utility.getBundleLongAsDate(bundle, AccessToken.EXPIRES_IN_KEY, new Date());
    String token = bundle.getString(AccessToken.ACCESS_TOKEN_KEY);

    // With Login v4, we now get back the actual permissions granted, so update the permissions
    // to be the real thing
    String grantedPermissions = bundle.getString("granted_scopes");
    if (!Utility.isNullOrEmpty(grantedPermissions)) {
        requestedPermissions = new ArrayList<String>(
                Arrays.asList(grantedPermissions.split(",")));
    }
    String deniedPermissions = bundle.getString("denied_scopes");
    List<String> declinedPermissions = null;
    if (!Utility.isNullOrEmpty(deniedPermissions)) {
        declinedPermissions = new ArrayList<String>(
                Arrays.asList(deniedPermissions.split(",")));
    }

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String signed_request = bundle.getString("signed_request");
    String userId = getUserIDFromSignedRequest(signed_request);

    return new AccessToken(
            token,
            applicationId,
            userId,
            requestedPermissions,
            declinedPermissions,
            source,
            expires,
            new Date());
}
项目:Move-Alarm_ORCA    文件:KatanaProxyLoginMethodHandler.java   
private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
    Bundle extras = data.getExtras();
    String error = extras.getString("error");
    if (error == null) {
        error = extras.getString("error_type");
    }
    String errorCode = extras.getString("error_code");
    String errorMessage = extras.getString("error_message");
    if (errorMessage == null) {
        errorMessage = extras.getString("error_description");
    }

    String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    if (error == null && errorCode == null && errorMessage == null) {
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(),
                    extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB,
                    request.getApplicationId());
            return LoginClient.Result.createTokenResult(request, token);
        } catch (FacebookException ex) {
            return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
        }
    } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
        return null;
    } else if (ServerProtocol.errorsUserCanceled.contains(error)) {
        return LoginClient.Result.createCancelResult(request, null);
    } else {
        return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
    }
}
项目:Move-Alarm_ORCA    文件:GetTokenLoginMethodHandler.java   
void onComplete(final LoginClient.Request request, final Bundle result) {
    AccessToken token = createAccessTokenFromNativeLogin(
            result,
            AccessTokenSource.FACEBOOK_APPLICATION_SERVICE,
            request.getApplicationId());
    LoginClient.Result outcome =
            LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
    loginClient.completeAndValidate(outcome);
}
项目:yelo-android    文件:Facebook.java   
@Override
public Bundle load() {
    Bundle bundle = new Bundle();

    if (accessToken != null) {
        TokenCachingStrategy.putToken(bundle, accessToken);
        TokenCachingStrategy.putExpirationMilliseconds(bundle, accessExpiresMillisecondsAfterEpoch);
        TokenCachingStrategy.putPermissions(bundle, stringList(pendingAuthorizationPermissions));
        TokenCachingStrategy.putSource(bundle, AccessTokenSource.WEB_VIEW);
        TokenCachingStrategy.putLastRefreshMilliseconds(bundle, lastAccessUpdateMillisecondsAfterEpoch);
    }

    return bundle;
}
项目:SocioBlood    文件:LoginMethodHandler.java   
public static AccessToken createAccessTokenFromWebBundle(
        Collection<String> requestedPermissions,
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) throws FacebookException {
    Date expires = Utility.getBundleLongAsDate(bundle, AccessToken.EXPIRES_IN_KEY, new Date());
    String token = bundle.getString(AccessToken.ACCESS_TOKEN_KEY);

    // With Login v4, we now get back the actual permissions granted, so update the permissions
    // to be the real thing
    String grantedPermissions = bundle.getString("granted_scopes");
    if (!Utility.isNullOrEmpty(grantedPermissions)) {
        requestedPermissions = new ArrayList<String>(
                Arrays.asList(grantedPermissions.split(",")));
    }
    String deniedPermissions = bundle.getString("denied_scopes");
    List<String> declinedPermissions = null;
    if (!Utility.isNullOrEmpty(deniedPermissions)) {
        declinedPermissions = new ArrayList<String>(
                Arrays.asList(deniedPermissions.split(",")));
    }

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String signed_request = bundle.getString("signed_request");
    String userId = getUserIDFromSignedRequest(signed_request);

    return new AccessToken(
            token,
            applicationId,
            userId,
            requestedPermissions,
            declinedPermissions,
            source,
            expires,
            new Date());
}
项目:SocioBlood    文件:KatanaProxyLoginMethodHandler.java   
private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
    Bundle extras = data.getExtras();
    String error = extras.getString("error");
    if (error == null) {
        error = extras.getString("error_type");
    }
    String errorCode = extras.getString("error_code");
    String errorMessage = extras.getString("error_message");
    if (errorMessage == null) {
        errorMessage = extras.getString("error_description");
    }

    String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    if (error == null && errorCode == null && errorMessage == null) {
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(),
                    extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB,
                    request.getApplicationId());
            return LoginClient.Result.createTokenResult(request, token);
        } catch (FacebookException ex) {
            return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
        }
    } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
        return null;
    } else if (ServerProtocol.errorsUserCanceled.contains(error)) {
        return LoginClient.Result.createCancelResult(request, null);
    } else {
        return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
    }
}
项目:SocioBlood    文件:GetTokenLoginMethodHandler.java   
void onComplete(final LoginClient.Request request, final Bundle result) {
    AccessToken token = createAccessTokenFromNativeLogin(
            result,
            AccessTokenSource.FACEBOOK_APPLICATION_SERVICE,
            request.getApplicationId());
    LoginClient.Result outcome =
            LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
    loginClient.completeAndValidate(outcome);
}
项目:QuizUpWinner    文件:Facebook.java   
public Bundle load()
{
  Bundle localBundle = new Bundle();
  if (Facebook.this.accessToken != null)
  {
    TokenCachingStrategy.putToken(localBundle, Facebook.this.accessToken);
    TokenCachingStrategy.putExpirationMilliseconds(localBundle, Facebook.this.accessExpiresMillisecondsAfterEpoch);
    TokenCachingStrategy.putPermissions(localBundle, Facebook.stringList(Facebook.this.pendingAuthorizationPermissions));
    TokenCachingStrategy.putSource(localBundle, AccessTokenSource.WEB_VIEW);
    TokenCachingStrategy.putLastRefreshMilliseconds(localBundle, Facebook.this.lastAccessUpdateMillisecondsAfterEpoch);
  }
  return localBundle;
}
项目:p2psafety    文件:Facebook.java   
@Override
public Bundle load() {
    Bundle bundle = new Bundle();

    if (accessToken != null) {
        TokenCachingStrategy.putToken(bundle, accessToken);
        TokenCachingStrategy.putExpirationMilliseconds(bundle, accessExpiresMillisecondsAfterEpoch);
        TokenCachingStrategy.putPermissions(bundle, stringList(pendingAuthorizationPermissions));
        TokenCachingStrategy.putSource(bundle, AccessTokenSource.WEB_VIEW);
        TokenCachingStrategy.putLastRefreshMilliseconds(bundle, lastAccessUpdateMillisecondsAfterEpoch);
    }

    return bundle;
}
项目:kognitivo    文件:WebViewLoginMethodHandler.java   
void onWebDialogComplete(LoginClient.Request request, Bundle values,
        FacebookException error) {
    LoginClient.Result outcome;
    if (values != null) {
        // Actual e2e we got from the dialog should be used for logging.
        if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
            e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
        }

        try {
            AccessToken token = createAccessTokenFromWebBundle(
                    request.getPermissions(),
                    values,
                    AccessTokenSource.WEB_VIEW,
                    request.getApplicationId());
            outcome = LoginClient.Result.createTokenResult(
                    loginClient.getPendingRequest(),
                    token);

            // Ensure any cookies set by the dialog are saved
            // This is to work around a bug where CookieManager may fail to instantiate if
            // CookieSyncManager has never been created.
            CookieSyncManager syncManager =
                    CookieSyncManager.createInstance(loginClient.getActivity());
            syncManager.sync();
            saveCookieToken(token.getToken());
        } catch (FacebookException ex) {
            outcome = LoginClient.Result.createErrorResult(
                    loginClient.getPendingRequest(),
                    null,
                    ex.getMessage());
        }
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(),
                    "User canceled log in.");
        } else {
            // Something went wrong, don't log a completion event since it will skew timing
            // results.
            e2e = null;

            String errorCode = null;
            String errorMessage = error.getMessage();
            if (error instanceof FacebookServiceException) {
                FacebookRequestError requestError =
                        ((FacebookServiceException)error).getRequestError();
                errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
                errorMessage = requestError.toString();
            }
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(),
                    null, errorMessage, errorCode);
        }
    }

    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    loginClient.completeAndValidate(outcome);
}
项目:Move-Alarm_ORCA    文件:WebViewLoginMethodHandler.java   
void onWebDialogComplete(LoginClient.Request request, Bundle values,
        FacebookException error) {
    LoginClient.Result outcome;
    if (values != null) {
        // Actual e2e we got from the dialog should be used for logging.
        if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
            e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
        }

        try {
            AccessToken token = createAccessTokenFromWebBundle(
                    request.getPermissions(),
                    values,
                    AccessTokenSource.WEB_VIEW,
                    request.getApplicationId());
            outcome = LoginClient.Result.createTokenResult(
                    loginClient.getPendingRequest(),
                    token);

            // Ensure any cookies set by the dialog are saved
            // This is to work around a bug where CookieManager may fail to instantiate if
            // CookieSyncManager has never been created.
            CookieSyncManager syncManager =
                    CookieSyncManager.createInstance(loginClient.getActivity());
            syncManager.sync();
            saveCookieToken(token.getToken());
        } catch (FacebookException ex) {
            outcome = LoginClient.Result.createErrorResult(
                    loginClient.getPendingRequest(),
                    null,
                    ex.getMessage());
        }
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(),
                    "User canceled log in.");
        } else {
            // Something went wrong, don't log a completion event since it will skew timing
            // results.
            e2e = null;

            String errorCode = null;
            String errorMessage = error.getMessage();
            if (error instanceof FacebookServiceException) {
                FacebookRequestError requestError =
                        ((FacebookServiceException)error).getRequestError();
                errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
                errorMessage = requestError.toString();
            }
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(),
                    null, errorMessage, errorCode);
        }
    }

    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    loginClient.completeAndValidate(outcome);
}
项目:SocioBlood    文件:WebViewLoginMethodHandler.java   
void onWebDialogComplete(LoginClient.Request request, Bundle values,
        FacebookException error) {
    LoginClient.Result outcome;
    if (values != null) {
        // Actual e2e we got from the dialog should be used for logging.
        if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
            e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
        }

        try {
            AccessToken token = createAccessTokenFromWebBundle(
                    request.getPermissions(),
                    values,
                    AccessTokenSource.WEB_VIEW,
                    request.getApplicationId());
            outcome = LoginClient.Result.createTokenResult(
                    loginClient.getPendingRequest(),
                    token);

            // Ensure any cookies set by the dialog are saved
            // This is to work around a bug where CookieManager may fail to instantiate if
            // CookieSyncManager has never been created.
            CookieSyncManager syncManager =
                    CookieSyncManager.createInstance(loginClient.getActivity());
            syncManager.sync();
            saveCookieToken(token.getToken());
        } catch (FacebookException ex) {
            outcome = LoginClient.Result.createErrorResult(
                    loginClient.getPendingRequest(),
                    null,
                    ex.getMessage());
        }
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(),
                    "User canceled log in.");
        } else {
            // Something went wrong, don't log a completion event since it will skew timing
            // results.
            e2e = null;

            String errorCode = null;
            String errorMessage = error.getMessage();
            if (error instanceof FacebookServiceException) {
                FacebookRequestError requestError =
                        ((FacebookServiceException)error).getRequestError();
                errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
                errorMessage = requestError.toString();
            }
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(),
                    null, errorMessage, errorCode);
        }
    }

    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    loginClient.completeAndValidate(outcome);
}