小编gok*_*urt的帖子

使用Facebook SDK 3.0.1 for Android获取电子邮件地址

我目前正在开发一个旨在通过Facebook帐户验证任何用户的应用程序.

我无法从用户的帐户获取用户电子邮件.我的代码如下

    private void signInWithFacebook() {

    SessionTracker mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() {

        public void call(Session session, SessionState state, Exception exception) {

        }
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    Session mCurrentSession = mSessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        mSessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(FacebookLoginActivity.this);

        if (openRequest != null) {
            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

            mCurrentSession.openForRead(openRequest);
        }
    }else {
        Request.executeMeRequestAsync(mCurrentSession, new …
Run Code Online (Sandbox Code Playgroud)

android facebook facebook-graph-api facebook-android-sdk

1
推荐指数
1
解决办法
2万
查看次数