android 4.0.4 的 Facebook 登录问题

Posted

技术标签:

【中文标题】android 4.0.4 的 Facebook 登录问题【英文标题】:Facebook login trouble with android 4.0.4 【发布时间】:2013-06-22 07:42:11 【问题描述】:

我在使用安装了 facebook 应用程序的 android 4.0.4 设备登录 facebook sdk 3.0.1 sdk 时遇到问题,代码在 Gingerbread 上运行良好

      private Session openActiveSession(Activity activity, boolean allowLoginUI,
                    StatusCallback callback, List<String> permissions,
                    Bundle savedInstanceState) 

                OpenRequest openRequest = new OpenRequest(activity)
                        .setPermissions(permissions)
                        .setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK)
                        .setCallback(callback)
                        .setDefaultAudience(SessionDefaultAudience.FRIENDS);

                Session session = Session.getActiveSession();
                if (session == null) 
                    if (savedInstanceState != null) 

                        session = Session.restoreSession(this, null, fbStatusCallback,
                                savedInstanceState);
                    
                    if (session == null) 
                        session = new Session(Login.this);

                    

                    Session.setActiveSession(session);
                    if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)
                            || allowLoginUI) 
                        session.openForRead(openRequest);
                        return session;
                    
                

                return null;
            



    private Session.StatusCallback fbStatusCallback = new Session.StatusCallback() 
        @Override
        public void call(Session session, SessionState state,
                Exception exception) 


             // callback for session state changes
            if (state.isOpened()) 


                Request.executeMeRequestAsync(session,
                        new Request.GraphUserCallback() 
                            @Override
                            public void onCompleted(GraphUser user,
                                    Response response) 
                                if (user != null) 
                                    if (response.getError() == null) 
                                        JSONObject jsonObj = user
                                                .getInnerJSONObject();
                                        String dat = jsonObj.toString();

                                        System.out
                                                .println("The facebook response is >>>>"
                                                        + dat);
                                        WebServices wb = new WebServices();
                                        sWrapper = wb.FacebookUserData(dat);

                                        if (progress != null)
                                            progress.dismiss();

                                        SignupTaskForFaceBook st = new SignupTaskForFaceBook();
                                        st.execute();
                                     else 
                                        // Do something with the error
                                    
                                
                            
                        );

            
        
    ;


@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode,
                resultCode, data);



        if(resultCode==RESULT_OK)
        
            progress = ProgressDialog.show(Login.this, "",
                    "Fetching facebook user data");
        
    

没有收到异常或消息,它要求我获得许可,并且永远不会调用回调

【问题讨论】:

【参考方案1】:

事实证明我从 openSSL 获得的密钥哈希不正确,所以我从

try 
PackageInfo info = getPackageManager().getPackageInfo("com.eatapp", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) 
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(signature.toByteArray());
    Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));

 catch (NameNotFoundException e) 

 catch (NoSuchAlgorithmException e) 


它开始工作了

【讨论】:

以上是关于android 4.0.4 的 Facebook 登录问题的主要内容,如果未能解决你的问题,请参考以下文章

Phonegap 2.5.0 地理定位不适用于 android 4.0.4

android4.0.4是啥意思?

使用 4.0.4 android 版本或 3.2 的设备运行 GCM 通知项目有啥区别吗?

无法为 Android 4.0.4 设备上的小部件启动接收器崩溃

android 4.0.4怎么才能点对点连接

HTML5 音频未在 Android 4.0.4 设备本机浏览器中多次播放