android - facebook示例无效

时间:2013-04-18 11:14:15

标签: android facebook

我是Facebook集成到Android应用程序的新手。我正在尝试运行来自Facebook getting started.的应用程序,但它无效。我没有得到用户名。为什么不工作?任何人都可以帮助我。

我为会话变量获得了以下内容。

session: {Session state:OPENING, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:360610310722942}

session opened: false

  public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 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) {
            final TextView welcome = (TextView) findViewById(R.id.welcome);
            System.out.println("session: " + session);
            System.out.println("session opened: " + session.isOpened());
            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) {

                                    welcome.setText("Hello "
                                            + user.getName() + "!");
                                }
                            }
                        });
            }

        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.out.println("onActivityResult");
    Session.getActiveSession().onActivityResult(this, requestCode,
            resultCode, data);
}

1 个答案:

答案 0 :(得分:1)

我有同样的问题,我只是解决了这个问题。 原因是我的项目处于沙盒模式。禁用沙盒模式,应用程序正常工作 enter image description here