Access token removed in Facebook Android SDK 4.0

耗尽温柔 提交于 2019-11-28 12:16:57

you can get access_token by using loginResult.getAccessToken().getToken(); as following code

 LoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

          String accessToken= loginResult.getAccessToken().getToken();

        }

By default the SDK will not log access tokens to logcat (this is to avoid leaking user tokens via the log).

You can, however, enable in debug mode a logging behavior to log the access token. Just add this when you're calling FacebookSdk.sdkInitialize(), but make sure to only do it when you're in debug mode:

if (BuildConfig.DEBUG) {
    FacebookSdk.setIsDebugEnabled(true);
    FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
}

You can get the token by using

 AccessToken.getCurrentAccessToken().getToken()

Using this you can get the token at any time, if you use the LoginResult, you get it only once at the time you log in, when you restart the app the onSuccess is not called.

If you need the profile after restarting, you use

Profile.getCurrentProfile();

If this returns null you are not loged in

I got the solution. I've execute GraphRequest method inside the separate thread. It is wrong approach. All asynch taks shoud be run inside the main thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!