28

有人可以帮我取消这段代码吗?这是 Facebook 提供的示例(关于如何连接到 FB 帐户 - https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/),但是标记线:

          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

已弃用。我尝试将其替换为:

    Request.newMeRequest( session, callback, executeAsync() );  

然而,代码嵌套得如此混乱,以至于把它搞砸了。我将不胜感激您能提供的任何帮助,因为我一整天都在做这件事。

// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {

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

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

        // 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() + "!");
          }
        }
      });
    }
  }
});

}

问候

4

1 回答 1

88

将您的替换Request.executeMeRequestAsync为:

Request.newMeRequest(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() + "!");
    }
  }
}).executeAsync();

即除了您调用稍微不同的方法并放在.executeAsync()最后之外,没有任何变化。

于 2013-09-18T17:46:03.637 回答