How to get user profile information from Facebook API Android

前端 未结 6 2074
半阙折子戏
半阙折子戏 2020-12-05 08:53

I\'m trying to get user profile information Facebook. Begins loading, I click to confirm permission to send my profile, again, continue loading but eventually get empty fiel

6条回答
  •  Happy的楠姐
    2020-12-05 09:21

    //register callback object for facebook result
        LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback() {
            @Override
            public void onSuccess(LoginResult loginResult) {
    
                //By Profile Class
                Profile profile = Profile.getCurrentProfile();
                if (profile != null) {
                    facebook_id=profile.getId();
                    f_name=profile.getFirstName();
                    m_name=profile.getMiddleName();
                    l_name=profile.getLastName();
                    full_name=profile.getName();
                    profile_image=profile.getProfilePictureUri(400, 400).toString();
                }
                //Toast.makeText(FacebookLogin.this,"Wait...",Toast.LENGTH_SHORT).show();
                GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
                        new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject object, GraphResponse response) {
                                try {
                                    email_id=object.getString("email");
                                    gender=object.getString("gender");
                                    String profile_name=object.getString("name");
                                    long fb_id=object.getLong("id"); //use this for logout
    
                                } catch (JSONException e) {
                                    // TODO Auto-generated catch block
                                    //  e.printStackTrace();
                                }
    
                            }
    
                        });
    
                request.executeAsync();
            }
    
            @Override
            public void onCancel() {
                Toast.makeText(FacebookLogin.this,getResources().getString(R.string.login_canceled_facebooklogin),Toast.LENGTH_SHORT).show();
                progress.dismiss();
            }
    
            @Override
            public void onError(FacebookException error) {
                Toast.makeText(FacebookLogin.this,getResources().getString(R.string.login_failed_facebooklogin),Toast.LENGTH_SHORT).show();
                progress.dismiss();
            }
        });
    

提交回复
热议问题