简体   繁体   中英

Facebook android sdk login dialog

I am using Facebook android sdk 3.0. what i want is user's id and access token which i am getting perfectly. The problem is if fb app is not installed on device and i tried to login, It does login but login dialog pops up again and even after clicking on close button of that dialog dialog keeps on popping until and unless i do the login again.

Here is my code :

if(v.getId()==imgLike.getId())
        {

            try
            {

                /*
                 * Logging in with Facebook
                 */

                try
                {


                    login_facebook();


                }catch(NullPointerException npx)
                {
                    npx.printStackTrace();
                }
                catch(Exception ex)
                {

                }

            }catch(Exception ex)
            {
                ex.printStackTrace();
            }


        } 

public void login_facebook()
    {


        try
        {
            Session.openActiveSession(acontext, true, new Session.StatusCallback() {

                @Override
                public void call(final Session session, SessionState state, Exception exception) {
                    // TODO Auto-generated method stub
                    if(session.isOpened())
                    {
                        List<String> permissions = session.getPermissions();
                        if (!isSubsetOf(PERMISSIONS, permissions)) {
                            pendingPublishReauthorization = true;
                            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(acontext, PERMISSIONS);
                            session.requestNewPublishPermissions(newPermissionsRequest);
                        }

                        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                            @Override
                            public void onCompleted(GraphUser user, Response response) {
                                // TODO Auto-generated method stub
                                if(user!=null)
                                {

                                    fbUserid=user.getId();
                                    fbAccessToken=session.getAccessToken();
                                    Log.i("User Name ", "Name : "+user.getName());
                                    Log.i("User Id ", "Id : "+user.getId());
                                    Log.i("User Access Token ", "Access Token : "+session.getAccessToken());


new LikeUrl().execute(carName.get(currentIMage));
                                }
                            }
                        });

                    }
                }
            });


        }catch(NullPointerException npx)
        {
            npx.printStackTrace();
        }catch(BadTokenException bdx)
        {
            bdx.printStackTrace();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try
        {
            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

        }catch(IllegalStateException ilgx)
        {
            ilgx.printStackTrace();
        }
        catch (NullPointerException e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }

    }



private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
        for (String string : subset) {
            if (!superset.contains(string)) {
                return false;
            }
        }
        return true;
    }

I have got the same problem when using the emulator without the Facebook app installed. In fact I think that the first dialog login is the one that requires the basic permissions (ie public profile and friend list) while the second one is for the additional permissions (read permissions in your case).

When I installed the official Facebook app the two dialog changed exactly according to this hypothesis.

If you want a single dialog or a single permission request here you can find a helpful discussion: link

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