我需要使用 android Facebook sdk 获取用户的电子邮件,我认为这是其中的内容,asMap
但似乎不能,
我试过这个
Session.openActiveSession(this, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
et_firstName.setText(user
.getFirstName());
et_lastName.setText(user
.getLastName());
Log.e("email",
user.asMap().get("email")
+ "");
} else {
}
}
});
}
}
});
但是log
给了我email
= null
。我真的很困惑为什么 Facebook 没有明确地给我们电子邮件。
任何帮助将不胜感激,在此先感谢。
编辑
Session sesssssss = null;
sesssssss.openForRead(new Session.OpenRequest(this)
.setPermissions(null));
Session.openActiveSession(this, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
et_firstName.setText(user
.getFirstName());
et_lastName.setText(user
.getLastName());
Log.e("data",
user.asMap().get("email")
+ "");
URL image_value;
try {
image_value = new URL(
"http://graph.facebook.com/"
+ user.getId()
+ "/picture");
iv_profileImage
.setImageBitmap(BitmapFactory
.decodeStream(image_value
.openConnection()
.getInputStream()));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
}
});
}
}
});
例外
07-31 14:55:44.054: E/AndroidRuntime(26398): FATAL EXCEPTION: main
07-31 14:55:44.054: E/AndroidRuntime(26398): java.lang.NullPointerException
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.Syriatel.EatTel.EditCustomerProfile.onOptionsItemSelected(EditCustomerProfile.java:89)
07-31 14:55:44.054: E/AndroidRuntime(26398): at android.app.Activity.onMenuItemSelected(Activity.java:2205)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:768)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:147)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
07-31 14:55:44.054: E/AndroidRuntime(26398): at android.view.View$PerformClick.run(View.java:9229)
07-31 14:55:44.054: E/AndroidRuntime(26398): at android.os.Handler.handleCallback(Handler.java:587)
07-31 14:55:44.054: E/AndroidRuntime(26398): at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 14:55:44.054: E/AndroidRuntime(26398): at android.os.Looper.loop(Looper.java:130)
07-31 14:55:44.054: E/AndroidRuntime(26398): at android.app.ActivityThread.main(ActivityThread.java:3701)
07-31 14:55:44.054: E/AndroidRuntime(26398): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 14:55:44.054: E/AndroidRuntime(26398): at java.lang.reflect.Method.invoke(Method.java:507)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
07-31 14:55:44.054: E/AndroidRuntime(26398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
07-31 14:55:44.054: E/AndroidRuntime(26398): at dalvik.system.NativeStart.main(Native Method)