5

我(想我)遵循了 Facebook 教程,但我无法让它正常工作。我正在尝试通过 FB 登录,然后获取有关用户的信息。我有:

 private Session.StatusCallback statusCallback = new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            System.out.println("GOOD");
            if (session.isOpened()) {
                System.out.println("AWESOME");
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                  // callback after Graph API response with user object
                  @Override
                  public void onCompleted(GraphUser user, Response response) {
                      m_user = user;
                      System.out.println("Hello " + user.getName());
                  }
                });
            }
        }

接着:

public void onBtnFacebookClick(final View v) {
      Session session = Session.getActiveSession();
      if (session == null) {
          session = new Session(this);
          Session.setActiveSession(session);
          if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
              session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
          }
      }
      if (!session.isOpened() && !session.isClosed()) {
          session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
      } else {
          Session.openActiveSession(this, true, statusCallback);
      }
  }

但似乎“AWESOME”从未被打印出来(“GOOD”被打印出来)即使我设法登录到 FB。或者我不明白什么session.isOpened()意思?

4

1 回答 1

9

好的,它现在可以工作了。我有两个问题。一个是我按照这些说明修复的不正确的哈希键。另一个是我不知道我必须重写这个方法:

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession()
          .onActivityResult(this, requestCode, resultCode, data);
  }
于 2013-04-28T23:13:56.457 回答