How to post Bitmap to facebook using facebook sdk?

前端 未结 2 868
遥遥无期
遥遥无期 2020-12-21 20:32

I don\'t find a correct solution to post an image to my facebook wall using facebook sdk. On stackOverflow I found the following solution but AsyncFacebookRunner and mAsyn

相关标签:
2条回答
  • 2020-12-21 21:10

    You have to use the function newUploadPhotoRequest see the documentation here :

    https://developers.facebook.com/docs/reference/android/3.0/Request#newUploadPhotoRequest%28Session,%20Bitmap,%20Callback%29

    0 讨论(0)
  • 2020-12-21 21:12

    The complete solution :

    Request.Callback uploadPhotoRequestCallback = new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            if (response.getError() != null) { 
                //post error
            } else{
                 String idRploadResponse = (String) response.getGraphObject().getProperty("id");
                 if (idRploadResponse!= null) { 
    
                    String fbPhotoAddress = "https://www.facebook.com/photo.php?fbid=" +idRploadResponse;                             
                 } else { 
                       //error
                 } 
    
            }
        }
    };
    
    
    @SuppressWarnings("deprecation")
    public void shareImg(View v) {
        Bitmap img = albero.getDrawingCache(); //I get Btimap from View 
    
        if (img != null) {
    
            Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), img,  uploadPhotoRequestCallback);
            Bundle parameters = request.getParameters(); // <-- THIS IS IMPORTANT
            parameters.putString("message", "My message");
            // add more params here
            request.setParameters(parameters);
            request.executeAsync();
        }
    }
    
    0 讨论(0)
提交回复
热议问题