Facebook的Andr​​oid SDK中登录对话框 [英] Facebook android sdk login dialog

查看:202
本文介绍了Facebook的Andr​​oid SDK中登录对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Facebook的Andr​​oid SDK中3.0。我想要的是我完全获取用户的ID和访问令牌。问题是如果设备上没有安装FB的应用程序,我试图登录,它不登录,但登录对话框,甚至单击该对话框对话框的关闭按钮后,弹出来再不断弹出之前,除非我再次进行登录。

下面是我的code:

 如果(v.getId()== imgLike.getId())
        {            尝试
            {                / *
                 *登录与Facebook
                 * /                尝试
                {
                    login_facebook();
                }赶上(NullPointerException异常NPX)
                {
                    npx.printStackTrace();
                }
                赶上(异常前)
                {                }            }赶上(异常前)
            {
                ex.printStackTrace();
            }
        }公共无效login_facebook()
    {
        尝试
        {
            Session.openActiveSession(acontext,真,新Session.StatusCallback(){                @覆盖
                公共无效电话(最后一届会议,SessionState会状态,异常除外){
                    // TODO自动生成方法存根
                    如果(session.isOpened())
                    {
                        清单<串GT;权限= session.getPermissions();
                        如果(!isSubsetOf(权限,权限)){
                            pendingPublishReauthorization =真;
                            Session.NewPermissionsRequest newPermissionsRequest =新Session.NewPermissionsRequest(acontext,权限);
                            session.requestNewPublishPermissions(newPermissionsRequest);
                        }                        Request.executeMeRequestAsync(会话,新Request.GraphUserCallback(){                            @覆盖
                            公共无效onCompleted(GraphUser用户,响应响应){
                                // TODO自动生成方法存根
                                如果(用户!= NULL)
                                {                                    fbUserid = user.getId();
                                    fbAccessToken = session.getAccessToken();
                                    Log.i(用户名,名称:+ user.getName());
                                    Log.i(用户ID,ID:+ user.getId());
                                    Log.i(用户访问令牌,访问令牌+ session.getAccessToken());
新LikeUrl()执行(carName.get(currentIMage))。
                                }
                            }
                        });                    }
                }
            });
        }赶上(NullPointerException异常NPX)
        {
            npx.printStackTrace();
        }赶上(BDX BadTokenException)
        {
            bdx.printStackTrace();
        }
        赶上(异常前)
        {
            ex.printStackTrace();
        }
    }@覆盖
    公共无效的onActivityResult(INT申请code,INT结果code,意图数据){
        super.onActivityResult(要求code,结果code,数据);
        尝试
        {
            Session.getActiveSession()的onActivityResult(这一点,要求code,结果code,数据)。        }赶上(IllegalStateException异常ilgx)
        {
            ilgx.printStackTrace();
        }
        赶上(NullPointerException异常五){
            // TODO:处理异常
            e.printStackTrace();
        }
        赶上(异常前)
        {
            ex.printStackTrace();
        }    }私人布尔isSubsetOf(收集和LT;弦乐>的子集,收集和LT;弦乐>超){
        对于(字符串字符串:子集){
            如果(!superset.contains(字符串)){
                返回false;
            }
        }
        返回true;
    }


解决方案

我已经使用没有安装Facebook应用程序模拟器时,得到了同样的问题。
事实上,我认为第一个对话框登录是需要的基本权限(即公开的个人资料和好友列表),而第二个是额外的权限(读你的情况的权限)的人。

当我安装了官方的Facebook应用程序,这两个对话框根据这一假说改变了完全一样。

如果你想有一个单独的对话框或单一许可请求在这里你可以找到一个有益的讨论:

链接

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 (i.e. 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

这篇关于Facebook的Andr​​oid SDK中登录对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆