I have created an application which has a login/register with Facebook option. The functionality is working fine for some profiles and causing issues on other profiles. I wanted to get the following data from the user's profile:
id,name,email,gender,birthday,location
The function dealing with Facebook login:
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();
}
The legitimate JSON output obtained using the above function:
{"id":"887845xxxxxxx0","name":"John Lenon","email":"[email protected]","gender":"male","birthday":"06\/20\/1988","location":{"id":"106517799384578","name":"New Delhi, India"}}
The illegitimate JSON output obtained using the above function:
{"id":"2709969xxxx35","gender":"male","email":"[email protected]","name":"Rohan Lalwani"}
The error shown in logcat:
01-12 15:13:08.699 30427-30427/? E/Error parsing returned user data: org.json.JSONException: No value for birthday
The second profile shows all values when checked in Facebook page.
The gradle dependency section:
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'
}
The library structure of the project:

Where am I going wrong? Why the profiles are behaving differently? What should be done to handle the issue?
This is possibly issue with facebook graph api as to fetch birthday,location permission's developer have to submit application for Review , Now for testing purpose facebook api only return these details only to the Administrators , Developers or Testers as maintained on Roles tab of facebook developer portal.
so In your case too it is the case where you can get birthday from api response as are trying to fetch those details from email id maintained on Roles tab and same response will not be delivered from graph api for other emailId's so on successful testing to get birthday in response from graph api for all users you have to Submit app for Review link .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With