简体   繁体   English

Facebook Android SDK登录对话框

[英]Facebook android sdk login dialog

I am using Facebook android sdk 3.0. 我正在使用Facebook android sdk 3.0。 what i want is user's id and access token which i am getting perfectly. 我想要的是用户的ID和访问令牌,我可以很好地获取它。 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. 问题是,如果设备上未安装fb应用,并且我尝试登录,它确实会登录,但登录对话框会再次弹出,即使单击该对话框的关闭按钮后,对话框也会一直弹出,直到并且除非我再次登录。

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. 在未安装Facebook应用程序的情况下使用模拟器时,我遇到了同样的问题。 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. 当我安装了官方的Facebook应用程序时,两个对话框完全根据此假设进行了更改。

If you want a single dialog or a single permission request here you can find a helpful discussion: link 如果要在此处进行单个对话框或单个权限请求,可以找到有用的讨论: 链接

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

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