ParseFaceBookUtil menggunakan Android tidak memberikan informasi pengguna

Saya menggunakan ParseFacebook SDK untuk aplikasi Android saya. Saya telah menggunakan parse kode SDK dari situs web sana, beberapa cuplikan kode diberikan di bawah ini, berhasil login dengan facebook, tetapi saya tidak dapat mengekstrak informasi facebook saya seperti: MyProfileImage, Nama Pengguna, dll.

Di Kelas Aplikasi:

ParseFacebookUtils.initialize(this);

Di kelas saya tempat saya menggunakan Login Facebook:

ParseFacebookUtils.logInWithReadPermissionsInBackground(SignInActivity.this, Arrays.asList("email", "user_photos", "public_profile", "user_friends"), new LogInCallback() {
                    @Override
                    public void done(ParseUser user, com.parse.ParseException e) {
                        if (user == null) {
                            Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
                        } else if (user.isNew()) {
                           }
);

Tolong bantu saya di sini untuk mengekstrak informasi untuk nama pengguna dan gambar profil. Terima kasih sebelumnya


person Android_Zapier    schedule 20.04.2016    source sumber


Jawaban (1)


Inilah yang berhasil untuk saya

public static void FaceBookLogin(final Activity context){
     ArrayList permissions=new ArrayList<String>();
    //permissions.add("publish_stream");
    permissions.add("user_likes");
    permissions.add("email");
    permissions.add("user_birthday");
    ParseFacebookUtils.logInWithReadPermissionsInBackground(context, permissions, new LogInCallback() {
        @Override
        public void done(ParseUser user, ParseException err) {
            if (user == null) {
                Toast.makeText(context,"You have cancelled to connect via facebook",Toast.LENGTH_SHORT);
                Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
            } else if (user.isNew()) {
                Toast.makeText(context,"You have successfully connected via facebook",Toast.LENGTH_SHORT);
                Log.d("MyApp", "User signed up and logged in through Facebook!");
                try {
                    GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject json, GraphResponse response) {
                            // Application code
                            if (response.getError() != null) {
                                System.out.println("ERROR");
                            } else {
                                System.out.println("Success");
                                String jsonresult = String.valueOf(json);
                                System.out.println("JSON Result" + jsonresult);

                                String fbUserId = json.optString("id");
                                String fbUserFirstName = json.optString("name");
                                String fbUserEmail = json.optString("email");
                                String fbUserProfilePics = "http://graph.facebook.com/" + fbUserId + "/picture?type=large";
                                ParseUser.getCurrentUser().setEmail(fbUserEmail);
                                ParseUser.getCurrentUser().put("First_Name",fbUserFirstName);
                                ParseUser.getCurrentUser().put("FaceBookUrl",fbUserProfilePics);
                                ParseUser.getCurrentUser().saveInBackground();
                            }
                            Log.v("FaceBook Response :", response.toString());
                        }
                    });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,name,email,gender, birthday");
                    request.setParameters(parameters);
                    request.executeAsync();
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(context,e.getMessage(),Toast.LENGTH_SHORT);
                }

                if (ParseUser.getCurrentUser().getBoolean("IsTermsAccepted")==true){
                    Intent intent = new Intent(context, MainActivity.class);
                    context.startActivity(intent);
                }else{
                    Utils.ShowTermsofUse(context);
                }
            } else {
                Toast.makeText(context,"You have successfully connected via facebook",Toast.LENGTH_SHORT);
                Log.d("MyApp", "User logged in through Facebook!");
                try {
                    GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject json, GraphResponse response) {
                            // Application code
                            if (response.getError() != null) {
                                System.out.println("ERROR");
                            } else {
                                System.out.println("Success");
                                String jsonresult = String.valueOf(json);
                                System.out.println("JSON Result" + jsonresult);

                                String fbUserId = json.optString("id");
                                String fbUserFirstName = json.optString("name");
                                String fbUserEmail = json.optString("email");
                                String fbUserProfilePics = "http://graph.facebook.com/" + fbUserId + "/picture?type=large";
                                ParseUser.getCurrentUser().setEmail(fbUserEmail);
                                ParseUser.getCurrentUser().put("First_Name",fbUserFirstName);
                                ParseUser.getCurrentUser().put("FaceBookUrl",fbUserProfilePics);
                                ParseUser.getCurrentUser().saveInBackground();
                            }
                            Log.v("FaceBook Response :", response.toString());
                        }
                    });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,name,email,gender, birthday");
                    request.setParameters(parameters);
                    request.executeAsync();
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(context,e.getMessage(),Toast.LENGTH_SHORT);

                }

                if (ParseUser.getCurrentUser().getBoolean("IsTermsAccepted")==true){
                    Intent intent = new Intent(context, MainActivity.class);
                    context.startActivity(intent);
                }else{
                    Utils.ShowTermsofUse(context);
                }
            }
            Toast.makeText(context,err.getMessage(),Toast.LENGTH_SHORT);
        }
    }) ;
}

Dan jangan lupa untuk memanggil onActivityResult:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    case FACEBOOK:
            ParseFacebookUtils.onActivityResult(FACEBOOK, resultCode, data);
            break;
    }

Semoga ini membantu

person Community    schedule 29.04.2016
comment
@Android_Zapier apakah Anda menemukan solusi untuk pertanyaan Anda? - person ; 27.06.2017