Facebook令牌返回空Android

时间:2013-07-11 05:29:54

标签: android facebook authentication

当我尝试使用面子书注册时,我遇到了问题,请在日志中获取以下内容

  07-11 10:15:07.757: W/com.facebook.Session(8910): Should not pass a read permission (user_likes) to a request for publish or manage authorization
07-11 10:15:07.772: W/com.facebook.Session(8910): Should not pass a read permission (email) to a request for publish or manage authorization
07-11 10:15:07.777: W/com.facebook.Session(8910): Should not pass a read permission (user_birthday) to a request for publish or manage authorization
07-11 10:15:07.787: W/com.facebook.Session(8910): Should not pass a read permission (user_location) to a request for publish or manage authorization
07-11 10:15:08.797: V/log_tag(8910): Token=
07-11 10:15:08.797: V/log_tag(8910): Token=false

我按照了facebook的正确文档 甚至使用代码生成SHA密钥并将其放在控制台上 禁用沙盒 启用脸书登录 禁用深层链接 但仍然没有运气 我用于脸书的代码如下:

facebookBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Session.openActiveSession(SignIn_Rewards.this, true, new Session.StatusCallback() {

                // callback when session changes state
                @Override
                public void call(Session session, SessionState state,
                        Exception exception) {

                    Log.v("log_tag", "Token=" + session.getAccessToken());
                    Log.v("log_tag", "Token=" + session.isOpened());

                    Session currentSession = Session.getActiveSession();

                    if (currentSession == null || currentSession.getState().isClosed()) 
                    {
                         session = new Session.Builder(SignIn_Rewards.this).build();
                        Session.setActiveSession(session);
                        currentSession = session;
                    }


                    else if(!currentSession.isOpened())
                    {
                        //Ask for username and password
                        OpenRequest op = new Session.OpenRequest(SignIn_Rewards.this);

                        op.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
                        op.setCallback(null);

                        List<String> permissions = new ArrayList<String>();
                        permissions.add("publish_stream");
                        permissions.add("user_likes");
                        permissions.add("email");
                        permissions.add("user_birthday");
                        permissions.add("user_location");
                        op.setPermissions(permissions);


                        session = new Session.Builder(SignIn_Rewards.this).build();
                        Session.setActiveSession(session);
                        session.openForPublish(op);
                    }
                    else if (session.isOpened()) {




                        // make request to the /me API
                        Request.executeMeRequestAsync(session,
                                new Request.GraphUserCallback() {

                                    // callback after Graph API response with user
                                    // object
                                    @Override
                                    public void onCompleted(GraphUser user,
                                            Response response) {
                                        if (user != null) {
                                           /* TextView welcome = (TextView) findViewById(R.id.welcome);
                                            welcome.setText("Hello "
                                                    + user.getName() + "!");*/
                                            finish();

                                            Log.d("User Name",""+user.getName()+"     "+user.getFirstName()+"    "+user.getLastName()+"    "+user.getProperty("email")+user.getBirthday()+user.getLocation().getProperty("name"));
                                        }
                                    }
                                });
                    }
                }
            });


        }
    }) ;

请在我错的地方纠正我

1 个答案:

答案 0 :(得分:0)

我一般都会发现这个问题是因为生成了错误的哈希密钥。而不是做所有keytool的东西尝试在你的onCreate之一粘贴此代码以生成正确的密钥并将其粘贴到Facebook上的应用程序部分。

PackageInfo info;
try {
    info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String something = new String(Base64.encode(md.digest(), 0));
        //String something = new String(Base64.encodeBytes(md.digest()));
        Log.e("hash key", something);
    }
} catch (NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
    Log.e("exception", e.toString());
}

这将在logcat中生成密钥。 检查this以了解更多正确生成哈希密钥的方法