我创建了一个具有Facebook选项登录/注册的应用程序。该功能适用于某些配置文件,并导致其他配置文件出现问题。我想从用户的个人资料中获取以下数据:
ID,名称,电子邮件地址,性别,生日,位置
处理Facebook登录的功能:
private void fromFaceBookLogin() {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
Log.e("onCompleted", ""+ParseUser.getCurrentUser().getObjectId());
if (jsonObject != null) {
JSONObject userProfile = new JSONObject();
try {
Log.e("jsonObject", jsonObject.toString());
userProfile.put("facebookId", jsonObject.getLong("id"));
userId = jsonObject.getLong("id");
userProfile.put("name", jsonObject.getString("name"));
//splitting first and last names
String[] parts = jsonObject.getString("name").split(" ");
firstName = parts[0]; // 004
lastName = parts[1]; // 034556
if (jsonObject.getString("gender") != null) {
userProfile.put("gender", jsonObject.getString("gender"));
}
Log.e("gender", jsonObject.getString("gender"));
if (jsonObject.getString("email") != null) {
userProfile.put("email", jsonObject.getString("email"));
}
email = jsonObject.getString("email");
Log.e("email", jsonObject.getString("email"));
birthDay = jsonObject.getString("birthday");
dateOfBirth = alterFaceBookDateObject(birthDay);
//countryFrom = pushBackCountry((String) jsonObject.getString("location").);
JSONObject weatherObservationItems = new JSONObject(jsonObject.getString("location"));
countryFrom = pushBackCountry( weatherObservationItems.getString("name"));
authData = userProfile;
try {
new obtainFaceBookProfilePhotoTask(LoadingFacebookDetails.this).execute().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
// goToPhotoBeforeSave(true);
} catch (JSONException e) {
Log.e("Error parsing returned user data", "" + e);
}
} else if (graphResponse.getError() != null) {
switch (graphResponse.getError().getCategory()) {
case LOGIN_RECOVERABLE:
Log.e("Authentication error",
"Authentication error: " + graphResponse.getError());
break;
case TRANSIENT:
Log.e("Transient error. Try again",
"Transient error. Try again. " + graphResponse.getError());
break;
case OTHER:
Log.e("Some other error",
"Some other error: " + graphResponse.getError());
break;
}
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday,location");
request.setParameters(parameters);
request.executeAsync();
}
使用上述功能获得的合法JSON输出:
{"id":"887845xxxxxxx0","name":"John Lenon","email":"john@yahoo.co.in","gender":"male","birthday":"06\/20\/1988","location":{"id":"106517799384578","name":"New Delhi, India"}}
使用上述功能获得的非法JSON输出:
{"id":"2709969xxxx35","gender":"male","email":"help@gmail.com","name":"Rohan Lalwani"}
logcat中显示的错误:
01-12 15:13:08.699 30427-30427/? E/Error parsing returned user data: org.json.JSONException: No value for birthday
第二个配置文件显示在Facebook页面中检查时的所有值。
gradle依赖部分:
dependencies {
compile project(':Viewpage:viewpage-library')
compile project(':CountryPicker')
compile project(':numberpicker-library')
compile('com.facebook.android:facebook-android-sdk:4.5.0') {
exclude module: 'bolts-android'
exclude module: 'support-v4'
}
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
//compile 'com.parse.bolts:bolts-android:1.1.+'
//compile fileTree(include: 'Parse-*.jar', dir: 'libs')
// compile fileTree(include: ['ParseFacebookUtilsV4-1.9.2.jar'], dir: 'libs')
compile fileTree(include: ['jsoup-1.7.3.jar'], dir: 'libs')
compile fileTree(include: ['ParseFacebookUtilsV4-1.10.3.jar'], dir: 'libs')
// compile fileTree(include: ['libGoogleAnalyticsServices.jar'], dir: 'libs')
//compile fileTree(dir: 'libs', include: ['android-support-multidex.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.traex.rippleeffect:library:1.3'
// compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
项目的图书馆结构:
我哪里错了?为什么配置文件的行为不同?应该怎么做来处理这个问题?
答案 0 :(得分:1)
这可能是 facebook graph api 的问题,因为要获取生日,位置权限的开发者必须提交审核的申请,现在出于测试目的,facebook api仅将这些详细信息仅返回到facebook developer portal的角色标签上维护的管理员,开发人员或测试人员。
所以在您的情况下也是如此,您可以从api响应中获得生日,因为尝试从角色标签上维护的电子邮件ID中获取这些详细信息,并且不会从图表中传递相同的响应其他emailId的api成功测试生日响应来自图api的所有用户,你必须提交app for Review link。
答案 1 :(得分:0)
检查以确保用户的公开个人资料中列出了他们的生日,我在解析相册中的图片时遇到过这种错误几次, 使用时
response.getJSONObject().getJSONArray("data").getJSONObject(i).getString("name");
在JSONArrays上如果图像没有描述我会得到错误:
org.json.JSONException: No value for name