gpt4 book ai didi

java - Facebook GraphRequest 在不同的个人资料上返回非法结果

转载 作者:太空狗 更新时间:2023-10-29 14:02:11 26 4
gpt4 key购买 nike

我已经创建了一个应用程序,它具有使用 Facebook 登录/注册的选项。该功能对某些配置文件运行良好,但会导致其他配置文件出现问题。我想从用户的个人资料中获取以下数据:

id,name,email,gender,birthday,location

处理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'

}

项目的库结构:

enter image description here

我哪里错了?为什么配置文件的行为不同?应该如何处理该问题?

最佳答案

这可能是 facebook graph api 获取生日、位置 权限的问题,开发者必须提交申请进行审核,现在进行测试目的 facebook api 仅将这些详细信息返回给 管理员、开发人员或测试人员,如 facebook developer portal角色 选项卡中维护的那样.

所以在您的情况下,您也可以从 api 响应中获取生日,因为您正在尝试从 Roles 选项卡上维护的电子邮件 ID 中获取这些详细信息,并且不会从图表中传递相同的响应用于其他 emailId 的 api 以便成功测试以从图形 api 响应所有用户的生日,您必须提交应用程序以供审核 link .

关于java - Facebook GraphRequest 在不同的个人资料上返回非法结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34740258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com