how to get email from Facebook sdk 4.0

后端 未结 1 453
逝去的感伤
逝去的感伤 2020-12-22 07:02

I\'m working on android Login with Facebook After login i want to save the data from Facebook i want to save the following data from Facebook

  1. First Name
  2. <
1条回答
  •  猫巷女王i
    2020-12-22 07:37

    Try This It's Work For me

     login.registerCallback(callbackManager, new FacebookCallback() {
            @Override
            public void onSuccess(LoginResult loginResult) {
    
                if (AccessToken.getCurrentAccessToken() != null) {
                    RequestData();
                }
            }
    
            @Override
            public void onCancel() {
    
            }
    
            @Override
            public void onError(FacebookException exception) {
            }
        });
    
    
    
    
    private void RequestData() {
    
        GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject object,GraphResponse response) {
    
                final JSONObject json = response.getJSONObject();
    
    
    
                try {
                    if(json != null){
                        text = "Name : "+json.getString("name")+"

    Email : "+json.getString("email")+"

    Profile link : "+json.getString("link"); /*details_txt.setText(Html.fromHtml(text)); profile.setProfileId(json.getString("id"));*/ Log.e(TAG, json.getString("name")); Log.e(TAG, json.getString("email")); Log.e(TAG, json.getString("id")); //web.loadData(text, "text/html", "UTF-8"); } } catch (JSONException e) { e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,link,email,picture"); request.setParameters(parameters); request.executeAsync(); }

    //Get Profile Picture from id

     public static Bitmap getFacebookProfilePicture(String userID){
        try {
            URL imageURL = new URL("https://graph.facebook.com/" + userID + "/picture?type=large");
            Log.e(TAG,imageURL.toString());
            try {
                bitmap = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    
        return bitmap;
    }
    

    0 讨论(0)
提交回复
热议问题