我创建了一个具有使用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":"[email protected]","gender":"male","birthday":"06\/20\/1988","location":{"id":"106517799384578","name":"New Delhi, India"}}
使用上述函数获得的非法JSON输出:
{"id":"2709969xxxx35","gender":"male","email":"[email protected]","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'
}
项目的库结构:
我要去哪里错了?为什么个人资料的行为有所不同?应该如何处理?
这可能是Facebook图形api的问题,例如要获取生日,位置权限的开发人员必须提交应用程序进行审查,现在出于测试目的,facebook api仅将这些详细信息返回给Facebook开发人员门户的“角色”选项卡上的管理员,开发人员或测试人员。
因此,在您的情况下,您也可以从api响应中获取生日,就像尝试从“角色”标签上维护的电子邮件ID中获取这些详细信息一样,其他apidId的图形api也不会传递相同的响应,因此成功进行测试即可来自graph api的所有生日,您必须为所有必须提交应用程序进行审阅的用户提供链接。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句