简体   繁体   English

使用Facebook注册后第二次打开我的android应用时,如何从第二次获取更新的用户数据?

[英]How to get updated user data from second time when when open my android app second time after sign up with Facebook?

I tried to get updated data from Graph API using accessToken but it always showing Logout button screen. 我试图使用accessToken从Graph API获取更新的数据,但它始终显示注销按钮屏幕。

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

@Override
protected void onDestroy() {
    super.onDestroy();
    if(isFromFb){
        accessTokenTracker.stopTracking();
    }
}
if(accessToken != null) {

            GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.d("TestLog user : " , object.toString());
                }
            });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender, birthday,picture.type(large),friends");
            request.setParameters(parameters);
            request.executeAsync();
        }

在此处输入图片说明

How to get latest profile data second time on wards in Facebook SDK 4.0 如何在Facebook SDK 4.0中第二次在病房中获取最新的配置文件数据

Try this You have programmatically log out the user after taking user details everytime like LoginManager.getInstance().logOut(); 尝试此操作每次获取用户详细信息后,您都可以通过编程方式注销用户,例如LoginManager.getInstance().logOut();

For more refer here:- http://coderzpassion.com/android-using-facebook-login-application-using-latest-facebook-sdk/ 有关更多信息,请参见: -http : //coderzpassion.com/android-using-facebook-login-application-using-latest-facebook-sdk/

Sorry I did a small mistake there final I got the answer. 对不起,我在那儿犯了一个小错误,最终我得到了答案。 I need to get current accessToken first. 我需要先获取当前的accessToken。 But earlier I taken only when onCurrentAccessTokenChanged method. 但是前面我只在使用onCurrentAccessTokenChanged方法时采用。

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

@Override
protected void onDestroy() {
    super.onDestroy();
    if(isFromFb){
        accessTokenTracker.stopTracking();
    }
}

if(accessToken != null) {

            GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.d("TestLog user : " , object.toString());
                }
            });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender, birthday,picture.type(large),friends");
            request.setParameters(parameters);
            request.executeAsync();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的应用在第二次打开时会崩溃? - Why does my app crash when I open it for the second time? 当我第二次运行DialogBox时,我的Android应用程序崩溃了 - My Android App crashes when i run a DialogBox for the second time 使用Facebook登录,Firebase在第二次登录Kotlin Android Studio时正在更改UID - Sign in with Facebook, Firebase is changing UID when signing in the second time, Kotlin Android Studio 当用户第二次打开片段或活动时如何停止重新加载数据? - How to stop reload the data when user open second time Fragment or activity? 应用程序第二次打开时未显示数据 - app not showing data when opend it for the second time FCM 通知返回在打开第二个通知时第二次获取相同的数据 - FCM notification return get same data second time when it open second notification 当片段第二次在android中加载时如何保存片段数据 - how to save fragment data when fragment loads second time in android 当AlertDialog应该第二次打开时,应用崩溃 - App crashes when AlertDialog is supposed to open for the second time Android:第二次打开片段时,在工具栏上消失“向上”按钮 - Android: Disappearing “up”-button at toolbar when opening fragment a second time 当我第二次打开应用程序时将数据存储在 Application 类中 - Store data in Application class when I open application second time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM