0

我在使用安装了 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");
        }
    }

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

4

1 回答 1

0

事实证明,我从 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) {

}

它开始工作

于 2013-06-25T12:24:18.073 回答