我目前正在开发一个应用程序,旨在通过使用 Facebook 帐户对任何用户进行身份验证.
I'm currently developing an application which aims to authenticate any user by using Facebook acoount.
我无法从用户帐户中获取用户电子邮件.我的代码在下面
I have a trouble in getting user email from user's account. My code is below
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 Request.GraphUserCallback() { public void onCompleted(GraphUser user, Response response) { Log.w("myConsultant", user.getId() + " " + user.getName() + " " + user.getLink() + " "+ response); } }); } }我在 Android 上使用 Facebook SDK 3.0.1.我已经设置了 Facebook Graph Api 所需的权限.在响应 xml 中,没有像电子邮件这样的字段.Facebook Sdk 文档不够好,我不知道如何获取电子邮件地址.
I am using Facebook SDK 3.0.1 for Android. I have set the permissions required by the Facebook Graph Api. In the response xml, there is no such field like email. Facebook Sdk documentations are not good enough and I don't know hot to obtain email address.
提前致谢.
推荐答案电子邮件不是返回的默认字段.相反,您应该创建一个 meRequest,并向其传递一个参数,例如:fields=email.
Email is not a default field that's returned. Instead, you should create a meRequest, and pass it a parameter like: fields=email.
Request me = Request.newMeRequest(mCurrentSession, new GraphRequestCallback() {...}); Bundle params = me.getParameters(); params.putString("fields", "email,name"); me.setParameters(params); me.executeAsync();更多推荐
使用 Facebook SDK 3.0.1 for Android 获取电子邮件地址
发布评论