在尝试访问用户详细信息时,我收到此错误:
07-29 14:49:47.343: W/System.err(2745): org.json.JSONException: No value for email
07-29 14:49:47.353: W/System.err(2745): at org.json.JSONObject.get(JSONObject.java:354)
07-29 14:49:47.374: W/System.err(2745): at org.json.JSONObject.getString(JSONObject.java:510)
07-29 14:49:47.374: W/System.err(2745): at com.example.healthcity.common.FacebookContainer$3$1.onCompleted(FacebookContainer.java:237)
07-29 14:49:47.409: W/System.err(2745): at com.facebook.Request$1.onCompleted(Request.java:264)
07-29 14:49:47.413: W/System.err(2745): at com.facebook.Request$4.run(Request.java:1240)
07-29 14:49:47.423: W/System.err(2745): at android.os.Handler.handleCallback(Handler.java:725)
07-29 14:49:47.423: W/System.err(2745): at android.os.Handler.dispatchMessage(Handler.java:92)
07-29 14:49:47.433: W/System.err(2745): at android.os.Looper.loop(Looper.java:137)
07-29 14:49:47.444: W/System.err(2745): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-29 14:49:47.444: W/System.err(2745): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 14:49:47.463: W/System.err(2745): at java.lang.reflect.Method.invoke(Method.java:511)
07-29 14:49:47.463: W/System.err(2745): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-29 14:49:47.485: W/System.err(2745): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-29 14:49:47.493: W/System.err(2745): at dalvik.system.NativeStart.main(Native Method)
我无法在回调方法上捕获断点。如果您遇到此错误,请帮助。
以下是我获取用户详细信息的代码:
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
//RFR//_("onSessionStateChange----------------");
/////////////// super.onSessionStateChange(state, exception);
if (state.isOpened()) {
readUserInfo(session);
} else if (state.isClosed()) {
// Session closed
}
}
private Request.GraphUserCallback graphCallback = new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
String name = user.getName();
String gender = (String) user.getProperty("gender");
String email = (String) user.getProperty("email");
String birthday = user.getBirthday();
Log.d("FB----->","name: "+ name +" gender: "+ gender +" email: "+ email +" birthday: " +birthday);
}
};
public void readUserInfo(Session session){
// make request to the /me API
Request.executeMeRequestAsync(session, graphCallback);
}
以下是我设置的权限:
openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location"));
这是我从浏览器检查时从图形 api 得到的响应:
{
"id": "1000000XXXXX930",
"name": "First Last",
"first_name": "First",
"last_name": "Last",
"link": "http://www.facebook.com/<myusername>",
"username": "<myusername>",
"gender": "male",
"locale": "en_US"
}