简体   繁体   中英

Android - Facebook SDK login

I try to login , the first time it pop out Facebook confirm page , than I click agree , than back to the same login page , but the button didn't change to logout , and I click again , it show a loading icon for 1 sec , than nothing happen , Facebook confirm page didn't pop out , can someone help , thanks!

public class FacebookLogin extends Activity {
CallbackManager callbackManager;
private AccessToken accessToken;

@Override
protected void onCreate(Bundle savedInstanceState) {
    FacebookSdk.sdkInitialize(getApplicationContext());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebooklogin);
    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.FaceBooklogin_button);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            accessToken = loginResult.getAccessToken();
            Log.d("FB","access token got.");
            Toast.makeText(FacebookLogin.this,"Gooooooooood",Toast.LENGTH_LONG).show();
            GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.d("FB","complete");
                    Log.d("FB",object.optString("name"));
                    Log.d("FB",object.optString("link"));
                    Log.d("FB",object.optString("id"));
                }
            });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,link");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            Log.d("FB","CANCEL");
            Toast.makeText(FacebookLogin.this,"CANCLE",Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(FacebookException error) {
            Toast.makeText(FacebookLogin.this,"Error",Toast.LENGTH_LONG).show();
        }
    });

}
}

and here is the LOG when I click login

02-10 02:55:44.141 23262-23262/com.addtw.aweino1 I/Timeline: Timeline:     Activity_launch_request id:com.addtw.aweino1 time:61774128
02-10 02:55:44.171 23262-23262/com.addtw.aweino1 W/ResourcesManager: getTopLevelResources: com.addtw.aweino1 for user  0
02-10 02:55:44.171 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* installDecor mIsFloating : false
02-10 02:55:44.171 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* installDecor flags : 8454400
02-10 02:55:44.181 23262-23262/com.addtw.aweino1 D/Activity: performCreate Call Injection manager
02-10 02:55:44.181 23262-23262/com.addtw.aweino1 I/InjectionManager: dispatchOnViewCreated > Target : com.facebook.FacebookActivity isFragment :false
02-10 02:55:44.191 23262-23262/com.addtw.aweino1 D/DisplayManager: DisplayManager()
02-10 02:55:44.201 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
02-10 02:55:44.201 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
02-10 02:55:44.221 23262-23289/com.addtw.aweino1 D/mali_winsys: new_window_surface returns 0x3000,  [720x1280]-format:1
02-10 02:55:44.241 23262-23262/com.addtw.aweino1 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2ff6ae77 time:61774222
02-10 02:55:44.481 23262-23419/com.addtw.aweino1 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-10 02:55:44.741 23262-23262/com.addtw.aweino1 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@35311897 time:61774726
02-10 02:55:50.701 23262-23412/com.addtw.aweino1 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

I got it ! need there more stuff

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

@Override
protected void onResume() {
    super.onResume();
    AppEventsLogger.activateApp(this);
}

@Override
protected void onPause() {
    super.onPause();
    AppEventsLogger.deactivateApp(this);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM