Unable to retrieve access token for facebook on real device

前端 未结 3 2039
攒了一身酷
攒了一身酷 2020-12-09 12:24

I did Facebook integration in my project, everything is fine on emulator. When it comes to run on real device it is not working. I think the problem is Facebook access token

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 12:51

    There is another answer for this question. We can have pre-installed facebook application to our mobile device , but we will not be interacting with the already installed application,i.e. we will not use single sign on ,better known as SSO(though it is recommended to use). We are having this method in facebook sdk. single sign-on may be disabled by passing FORCE_DIALOG_AUTH as the activityCode parameter in your call to authorize().

    public void authorize(Activity activity, String[] permissions,
            int activityCode, final DialogListener listener)
    

    Here the third parameter plays the role i.e. activityCode.Now lets see its role

     if (activityCode >= 0) {
            singleSignOnStarted = startSingleSignOn(activity, mAppId,
                    permissions, activityCode);
        }
        // Otherwise fall back to traditional dialog.
        if (!singleSignOnStarted) {
            startDialogAuth(activity, permissions);
        }
    

    It means if we want to be untouched with the pre installed facebook application we have to pass activityCode with less than 0 (< 0) value.Now in your main activity where facebook api is called use

    int FORCE_DIALOG_AUTH =-1;
    mFacebook.authorize(this, new String[] { "publish_stream",
            "read_stream", "offline_access", "friends_birthday",
            "user_birthday", "email", "read_friendlists",
            "manage_friendlists" },FORCE_DIALOG_AUTH , new LoginDialogListener());
    

    If we would like to force the use of legacy dialog-based authorization, pass FORCE_DIALOG_AUTH for this parameter. Otherwise just omit this parameter and Facebook will use a suitable default. It was just to solve the problem from SSO.

提交回复
热议问题