Facebook login fails on some devices

后端 未结 10 2387
遥遥无期
遥遥无期 2021-01-04 21:11

I have implemented the Facebook login and it works fine on some devices/AVDs. My development device is a Gingerbread phone, but testing it with a 4.1.1 device, it simply doe

相关标签:
10条回答
  • 2021-01-04 21:54

    Try inserting this line where you define your login button in the java source code

    LoginButton fb_button = (LoginButton)findViewById(//your resource id);
    fb_button.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
    
    0 讨论(0)
  • 2021-01-04 21:57
    List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    
    
    
    //start Facebook session
    openActiveSession(this, true, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                //make request to the /me API
    
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            String firstName = user.getFirstName();
                            String lastName = user.getLastName();
                            String id = user.getId();
                            String email=null;
                            try {
                                email = user.getProperty("email").toString();
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
    
                            String gender = (String) user.getProperty("gender");
                            String birthday = user.getBirthday();
    
    
    
                        //welcome.setText("Hello \n" + firstName+"\n"+lastName+"\n"+email+"\n"+gender+"\n"+birthday+"!");
    
    
    
    
                        if(firstName!=null)
                        {
    
    
                              SharedPreferences.Editor editor = settings.edit();
    
                                editor.putString("fligin", "1");
                                editor.putString("firstName", firstName);
                                editor.putString("lastName", lastName);
                                editor.putString("email", email);
                                editor.putString("gender", gender);
                                editor.putString("birthday", birthday);
                                editor.commit();
    
                            Intent intent=new Intent(getApplicationContext(), RegistrationOneActivity.class);
                            startActivity(intent);
                            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
    
                            finish();
                        }
                        else {
    
                            Toast.makeText(getApplicationContext(),"Person information is null", Toast.LENGTH_SHORT).show();
    
                        finish();
                            }
    
    
    
                        }
                    }
                });
             }
         }
     }, permissions);
    
    0 讨论(0)
  • 2021-01-04 22:01

    I think facebook login error mostly occur so to solve this issue you follow there tutorial step by step again with patience.

    Other wise its very difficult to solve your problem here. So you can refer this link.

    http://developers.facebook.com/android/

    I hope you will success.

    0 讨论(0)
  • 2021-01-04 22:04

    There is certainly a conflict between your stock app and the SDK. So if you don't want to uninnstall the stock HTC app and still use the SDK 3.0 I think your best bet without modying the source code of the sdk would be to disable SSO and login only through webview.

    This can easily be done by adding the SessionLoginBehavior.SUPRESS_SSO everytime you try to open a new session. Here is a sample I changed from the SessionLoginSample (LoginUsingActivityActivity) from the Facebook SDK to show you what to do :

    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        Session session = Session.getActiveSession();
        if (session == null) {
            if (savedInstanceState != null) {
                session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
            }
            if (session == null) {
                session = new Session(this);
            }
            Session.setActiveSession(session);
    
            //add the check, for if session is opened
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED) || !session.getState().isOpened()) {
                //Add the suppress SSO behavior to force webview auth dialog to popup
                session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO));
            }
        }
      ...
    }
    //then put your code in the statusCallback method or keep it in the session state change listener
    

    Otherwise if you don't mind changing the facebook sdk code, you should check this out

    0 讨论(0)
提交回复
热议问题