Java 类com.facebook.AccessTokenTracker 实例源码

项目:kognitivo    文件:VideoUploader.java   
private static void registerAccessTokenTracker() {
    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(
                AccessToken oldAccessToken,
                AccessToken currentAccessToken) {
            if (oldAccessToken == null) {
                // If we never had an access token, then there would be no pending uploads.
                return;
            }

            if (currentAccessToken == null ||
                    !Utility.areObjectsEqual(
                            currentAccessToken.getUserId(),
                            oldAccessToken.getUserId())) {
                // Cancel any pending uploads since the user changed.
                cancelAllRequests();
            }
        }
    };
}
项目:PlatePicks-Android    文件:LoginFragment.java   
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());

    callbackManager = CallbackManager.Factory.create();

    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {

        }
    };

    profileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            //Toast.makeText(getActivity(), "newProfile", Toast.LENGTH_SHORT).show();
            //displayMessage(currentProfile);

        }
    };

    accessTokenTracker.startTracking();
    profileTracker.startTracking();
}
项目:Rocket.Chat-android    文件:LoginActivity.java   
private void setupFacebookLogin() {
    //TODO: Check if facebook login is actvated in the server
    String appId = FacebookSdk.getApplicationId();
    Timber.d("appId: " + appId);
    if (appId != null) {
        mCallbackManager = CallbackManager.Factory.create();
        mFacebookButton.setReadPermissions(PERMISSIONS);
        mFacebookButton.registerCallback(mCallbackManager, mFacebookCallback);
        mAccessTokenTracker = new AccessTokenTracker() {
            @Override
            protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
                if (currentAccessToken != null) {
                    mRxRocketMethods.loginWithFacebook(currentAccessToken.getToken(), currentAccessToken.getExpires().getTime() - new Date().getTime())
                            .subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(mLoginSubscriber);

                }
            }
        };

    } else {
        mFacebookButton.setVisibility(View.GONE);
    }

}
项目:MaraudersMapMultiUser    文件:SplashScreenActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash_screen);
    FacebookSdk.sdkInitialize(getApplicationContext());

    AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
            updateWithToken(newAccessToken);
        }

    };
    accessTokenTracker.startTracking();
    updateWithToken(AccessToken.getCurrentAccessToken());
}
项目:Movie-Maniac-Android    文件:BaseActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    mCallbackManager = CallbackManager.Factory.create();

    mAccessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken == null) {
                //logout from facebook
                EventBus.getDefault().post(new UserEvent.LogoutEvent());
            }
        }
    };
}
项目:SocioBlood    文件:VideoUploader.java   
private static void registerAccessTokenTracker() {
    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(
                AccessToken oldAccessToken,
                AccessToken currentAccessToken) {
            if (oldAccessToken == null) {
                // If we never had an access token, then there would be no pending uploads.
                return;
            }

            if (currentAccessToken == null ||
                    !Utility.areObjectsEqual(
                            currentAccessToken.getUserId(),
                            oldAccessToken.getUserId())) {
                // Cancel any pending uploads since the user changed.
                cancelAllRequests();
            }
        }
    };
}
项目:AndroidBlueprints    文件:FacebookHelper.java   
private void initAccessTokenTracker() {
    mAccessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            // Set the access token using
            // currentAccessToken when it's loaded or set.
            // If the access token is available already assign it.
            mFacebookAccessToken = AccessToken.getCurrentAccessToken();
            //                Toast.makeText(mActivity, "Facebook current Access Token changed", Toast.LENGTH_SHORT)
            //                        .show();
        }
    };
}
项目:uPods-android    文件:LoginMaster.java   
private void initFacebook() {
    FacebookSdk.setApplicationId(Config.FACEBOOK_APP_ID);

    AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
            Logger.printInfo(LOG_TAG, "Is loged in with facebook");
        }
    };
    accessTokenTracker.startTracking();
}
项目:Material-Login    文件:Login.java   
private void setupTokenTracker() {
    mTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            Log.d("scion", "" + currentAccessToken);
        }
    };
}
项目:androidApp    文件:FacebookAccountLoginner.java   
@Override
public void login() {
    Log.d(TAG, "Login Facebook Account");
    final AccessTokenTracker tracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            Log.d(TAG, "onCurrentAccessTokenChanged");
            this.stopTracking();
            loginFragment.startLoading();
            dataManager.getCredentials(new CredentialsListener() {
                @Override
                public void onSuccess(SocialMediaAccount account) {
                    loginFragment.stopLoading();

                    listener.onSuccess(account);
                }

                @Override
                public void onError(ServerStatusCode error) {
                    loginFragment.stopLoading();
                    listener.onError(error);
                }
            });
        }
    };
    Log.d(TAG, "Starting tracker");
    tracker.startTracking();
    LoginManager.getInstance().logInWithReadPermissions(loginFragment, Arrays.asList("email", "public_profile"));


    TranSappApplication.getAppSharedPreferences().edit().putBoolean(
            TranSappApplication.getAppContext().
                    getString(R.string.facebook_log_in), true
    ).apply();
}
项目:YourAppIdea    文件:FacebookDelegate.java   
public FacebookDelegate(UserHelper userHelper, Activity activity, String... permissions) {
    this.mUserHelper = userHelper;

    FacebookSdk.sdkInitialize(activity.getApplicationContext());
    mCallbackManager = CallbackManager.Factory.create();
    mActivity = activity;
    mPermissions = Arrays.asList(permissions);
    LoginManager.getInstance().registerCallback(mCallbackManager, this);

    mAccessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(
                AccessToken oldAccessToken,
                AccessToken currentAccessToken) {
            mAccessToken = AccessToken.getCurrentAccessToken();
        }
    };

    mProfileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(
                Profile oldProfile,
                Profile currentProfile) {
            if (currentProfile == null) {
                mUserHelper.setCurrentUser(null);

                // Logout
                if (oldProfile != null && mUserSessionCallback != null) {
                    mUserSessionCallback.onLogout();
                }
            } else {
                requestUserData();
            }
        }
    };

    // If the access token is available already assign it.
    mAccessToken = AccessToken.getCurrentAccessToken();
}
项目:Guanajoven    文件:LoginFragment.java   
/**
 * Método de arranque. Se instancian todas las referencias del login con Google y Facebook.
 * @param savedInstanceState {Bundle}
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Se instancian las GoogleSignInOptions y el GoogleApiClient.
    googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestProfile()
            .build();

    if(googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(getActivity())
                .enableAutoManage(getActivity(), new GoogleApiClient.OnConnectionFailedListener() {
                    @Override
                    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                        OKDialog.showOKDialog(getActivity(), "Error", "Hubo un error en la conexión, reintentar más adelante");
                    }
                })
                .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions).addApi(LocationServices.API)
                .build();
    }


    //Configuración de Facebook.
    callbackManager = CallbackManager.Factory.create();
    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {

        }
    };
    profileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { }
    };
    accessTokenTracker.startTracking();
    profileTracker.startTracking();


    //Instancia de las preferencias.
    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());


    //Instancia de retrofit para servicio de API
    retrofit = ((MyApplication) getActivity().getApplication()).getRetrofitInstance();
    usuarioAPI = retrofit.create(UsuarioAPI.class);

}
项目:Firebase-Login-Example-Project    文件:MainActivity.java   
private void initEntities() {
    // ----- For sign in with email ----- //
    authListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                signInStatusMessage("Signed in: "
                        + "user.getDisplayName() " + user.getDisplayName() + " \n"
                        + "user.getUid() " + user.getUid() + " \n"
                        + "user.getProviderId() " + user.getProviderId() + " \n"
                );
                isSignedIn = true;
            } else {
                signInStatusMessage("Signed out.");
                isSignedIn = false;
            }
        }
    };


    // ----- For sign in with facebook ----- //
    btnFacebook.registerCallback(facebookCallbackManager, new FacebookCallback<LoginResult>(){
        @Override
        public void onSuccess(LoginResult loginResult) {
            isSignedIn = true;
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            isSignedIn = false;
        }

        @Override
        public void onError(FacebookException error) {
            isSignedIn = false;
        }
    });

    // ----- For sign OUT with facebook ----- //
    AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken accessToken, AccessToken accessToken2) {
            if (accessToken2 == null)  signOut();
        }
    };



    // ----- For sign in with google ----- //
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    // nothing
                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

}
项目:getsocial-android-sdk    文件:BaseFragment.java   
protected void addFacebookUserIdentity(final CompletionCallback completionCallback) {
    final CompletionCallback wrapped = new CompletionCallback() {
        @Override
        public void onSuccess() {
            completionCallback.onSuccess();
            setFacebookDisplayName();
            setFacebookAvatar();
        }

        @Override
        public void onFailure(GetSocialException e) {
            completionCallback.onFailure(e);
        }
    };
    final AddUserIdentityOutcomeCallback addUserIdentityOutcomeCallback = new AddUserIdentityOutcomeCallback() {
        @Override
        public void onSuccess() {
            _log.logInfoAndToast("Added Facebook identity successfully");
            wrapped.onSuccess();
        }

        @Override
        public void onFailure(Throwable throwable) {
            _log.logInfoAndToast("Adding Facebook identity failed : " + throwable);
            disconnectFromFacebook();
            wrapped.onFailure(upgradeToGetSocialException(throwable));
        }

        @Override
        public void onConflictResolvedWithCurrent() {
            _log.logInfoAndToast("Conflict adding Facebook user identity resolved with current");
            disconnectFromFacebook();
        }

        @Override
        public void onConflictResolvedWithRemote() {
            _log.logInfoAndToast("Conflict adding Facebook user identity resolved with remote");
            wrapped.onSuccess();
        }
    };

    final AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, @Nullable AccessToken newAccessToken) {

            if (newAccessToken == null) {
                addUserIdentityOutcomeCallback.onFailure(new IllegalStateException("Facebook SDK did not provide an AccessToken"));
                return;
            }

            stopTracking();

            final String tokenString = newAccessToken.getToken();

            addIdentity(AuthIdentity.createFacebookIdentity(tokenString), addUserIdentityOutcomeCallback);
        }
    };
    accessTokenTracker.startTracking();
    LoginManager.getInstance().logInWithReadPermissions(getActivity(), FACEBOOK_PERMISSIONS);
}
项目:androidApp    文件:FacebookAccountLoader.java   
@Override
public void load(final CredentialsListener listener) {
    Log.d(TAG, "Loading account");
    boolean hasFacebookLoggedIn =
            TranSappApplication.getAppSharedPreferences()
                    .getBoolean(
                            TranSappApplication.getAppContext().
                                    getString(R.string.facebook_log_in), false);

    if (!hasFacebookLoggedIn) {
        Log.d(TAG, "First time login");
        listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
        return;
    }

    if (AccessToken.getCurrentAccessToken() != null) {
        Log.d(TAG, "loadDataFromToken");
        dataManager.getCredentials(listener);
        return;
    }
    final Timer timer = new Timer();
    final AccessTokenTracker tracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken,
                                                   AccessToken currentAccessToken) {
            timer.cancel();
            stopTracking();
            if (currentAccessToken == null) {
                Log.d(TAG, "Facebook logged out");
                listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
            } else {
                Log.d(TAG, "Facebook logged in");
                dataManager.getCredentials(listener);
            }
        }
    };

    Log.d(TAG, "Starting tracker");
    tracker.startTracking();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            tracker.stopTracking();
            Log.d(TAG, "Time up");
            listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
        }
    }, 5000);
}
项目:AndroidBlueprints    文件:FacebookHelper.java   
/**
 * Gets facebook access token tracker.
 *
 * @return the facebook access token tracker
 */
public AccessTokenTracker getFacebookAccessTokenTracker() {
    return this.mAccessTokenTracker;
}