Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Facebook GraphRequest在不同的个人资料上返回非法结果_Java_Android_Json_Facebook_Facebook Graph Api - Fatal编程技术网

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

Java Facebook GraphRequest在不同的个人资料上返回非法结果,java,android,json,facebook,facebook-graph-api,Java,Android,Json,Facebook,Facebook Graph Api,我已经创建了一个应用程序,它有一个登录/注册Facebook选项。该功能在某些配置文件中运行良好,并导致其他配置文件出现问题。我想从用户的个人资料中获取以下数据: 身份证、姓名、电子邮件、性别、生日、地点 处理Facebook登录的功能: private void fromFaceBookLogin() { GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),

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

身份证、姓名、电子邮件、性别、生日、地点

处理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"}}
{"id":"2709969xxxx35","gender":"male","email":"help@gmail.com","name":"Rohan Lalwani"}
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'

}
使用上述函数获得的非法JSON输出:

{"id":"887845xxxxxxx0","name":"John Lenon","email":"john@yahoo.co.in","gender":"male","birthday":"06\/20\/1988","location":{"id":"106517799384578","name":"New Delhi, India"}}
{"id":"2709969xxxx35","gender":"male","email":"help@gmail.com","name":"Rohan Lalwani"}
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'

}
logcat中显示的错误:

01-12 15:13:08.699 30427-30427/? E/Error parsing returned user data: org.json.JSONException: No value for birthday
第二个配置文件显示在Facebook页面中选中时的所有值

渐变依赖项部分:

{"id":"887845xxxxxxx0","name":"John Lenon","email":"john@yahoo.co.in","gender":"male","birthday":"06\/20\/1988","location":{"id":"106517799384578","name":"New Delhi, India"}}
{"id":"2709969xxxx35","gender":"male","email":"help@gmail.com","name":"Rohan Lalwani"}
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'

}
项目的库结构:

{"id":"887845xxxxxxx0","name":"John Lenon","email":"john@yahoo.co.in","gender":"male","birthday":"06\/20\/1988","location":{"id":"106517799384578","name":"New Delhi, India"}}
{"id":"2709969xxxx35","gender":"male","email":"help@gmail.com","name":"Rohan Lalwani"}
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 graph api的问题,因为获取生日、地点权限的开发者必须提交申请进行审查,现在出于测试目的,facebook api仅将这些详细信息返回给管理员,开发人员或测试人员在的角色选项卡上维护


因此,在您的情况下,您也可以从api响应中获得生日,因为您正试图从维护在角色选项卡上的电子邮件id中获取这些详细信息,并且对于其他电子邮件id的成功测试,graph api将不会提供相同的响应,以便从graph api中为您必须的所有用户获得生日响应提交应用程序进行审查

检查以确保用户的公共档案中列出了他们的生日,我在分析相册中的图像时遇到过几次这个错误, 使用时

response.getJSONObject().getJSONArray("data").getJSONObject(i).getString("name");
在JSONArray上,如果图像没有描述,我将得到错误:

org.json.JSONException: No value for name