Java Code Examples for com.facebook.AccessToken#getToken()

The following examples show how to use com.facebook.AccessToken#getToken() . 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: FacebookNetwork.java    From EasyLogin with MIT License 6 votes vote down vote up
@Override
public void onSuccess(LoginResult loginResult) {

    final AccessToken fbAccessToken = loginResult.getAccessToken();

    if (permissions.contains(EMAIL_PERMISSION_FIELD)) {
        addEmailToToken(fbAccessToken);
        return;
    }

    String token = fbAccessToken.getToken();
    String userId = fbAccessToken.getUserId();
    accessToken = new com.maksim88.easylogin.AccessToken.Builder(token)
            .userId(userId)
            .build();
    listener.onLoginSuccess(getNetwork());
}
 
Example 2
Source File: LoginClient.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static AccessToken createFromTokenWithRefreshedPermissions(
        AccessToken token,
        Collection<String> grantedPermissions,
        Collection<String> declinedPermissions) {
    return new AccessToken(
            token.getToken(),
            token.getApplicationId(),
            token.getUserId(),
            grantedPermissions,
            declinedPermissions,
            token.getSource(),
            token.getExpires(),
            token.getLastRefresh());
}
 
Example 3
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
private void signInWithFacebook(AccessToken token) {
        Log.d(TAG, "signInWithFacebook:" + token.getToken());
        AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
        final String tokenString = token.getToken();
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
//
//                        startActivity(new Intent(SignUp09.this, Dashboard.class));
                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "signInWithCredential", task.getException());
                            Toast.makeText(LoginActivity.this, "Sorry for inconvenience,Please try again..",
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            //signInFacebook(tokenString);
                            Toast.makeText(LoginActivity.this, "Welcome..!", Toast.LENGTH_SHORT).show();
                            checkUserExist();
                        }
                    }


                });
    }
 
Example 4
Source File: FacebookImpl.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public com.codename1.io.AccessToken getAccessToken() {
    AccessToken fbToken = AccessToken.getCurrentAccessToken();
    if (fbToken != null) {
        String token = fbToken.getToken();
        Date ex = fbToken.getExpires();
        long diff = ex.getTime() - System.currentTimeMillis();
        diff = diff / 1000;
        com.codename1.io.AccessToken cn1Token = new com.codename1.io.AccessToken(token, "" + diff);
        return cn1Token;
    }
    return null;
}
 
Example 5
Source File: WebViewLoginMethodHandler.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@Override
boolean tryAuthorize(final LoginClient.Request request) {
    Bundle parameters = new Bundle();
    if (!Utility.isNullOrEmpty(request.getPermissions())) {
        String scope = TextUtils.join(",", request.getPermissions());
        parameters.putString(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
        addLoggingExtra(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
    }

    DefaultAudience audience = request.getDefaultAudience();
    parameters.putString(
            ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE, audience.getNativeProtocolAudience());

    AccessToken previousToken = AccessToken.getCurrentAccessToken();
    String previousTokenString = previousToken != null ? previousToken.getToken() : null;
    if (previousTokenString != null
            && (previousTokenString.equals(loadCookieToken()))) {
        parameters.putString(
                ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
                previousTokenString);
        // Don't log the actual access token, just its presence or absence.
        addLoggingExtra(
                ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
                AppEventsConstants.EVENT_PARAM_VALUE_YES);
    } else {
        // The call to clear cookies will create the first instance of CookieSyncManager if
        // necessary
        Utility.clearFacebookCookies(loginClient.getActivity());
        addLoggingExtra(
                ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
                AppEventsConstants.EVENT_PARAM_VALUE_NO);
    }

    WebDialog.OnCompleteListener listener = new WebDialog.OnCompleteListener() {
        @Override
        public void onComplete(Bundle values, FacebookException error) {
            onWebDialogComplete(request, values, error);
        }
    };

    e2e = LoginClient.getE2E();
    addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);

    FragmentActivity fragmentActivity = loginClient.getActivity();
    WebDialog.Builder builder = new AuthDialogBuilder(
            fragmentActivity,
            request.getApplicationId(),
            parameters)
            .setE2E(e2e)
            .setIsRerequest(request.isRerequest())
            .setOnCompleteListener(listener)
            .setTheme(FacebookSdk.getWebDialogTheme());
    loginDialog = builder.build();

    FacebookDialogFragment dialogFragment = new FacebookDialogFragment();
    dialogFragment.setRetainInstance(true);
    dialogFragment.setDialog(loginDialog);
    dialogFragment.show(fragmentActivity.getSupportFragmentManager(),
            FacebookDialogFragment.TAG);

    return true;
}
 
Example 6
Source File: AppEventsLogger.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
AccessTokenAppIdPair(AccessToken accessToken) {
    this(accessToken.getToken(), FacebookSdk.getApplicationId());
}