简体   繁体   中英

upload photo to Facebook from Android

I'm trying to upload photo to Facebook from my Android App and it works fine, photo is uploaded, problem is, Facebook app doesn't open, my App simply uploads photo directly to News Feed, but without option to maybe discard it, or change text or antything, so what i would like is to open facebook post with my image attached but not posted until i click the "post"

here is my code :

Bitmap img = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_launcher);
    Request uploadRequest = Request.newUploadPhotoRequest(
                    Session.getActiveSession(), img, new Request.Callback() {
                @Override
                public void onCompleted(Response response) {
                    Toast.makeText(MyActivity.this,
                            "Photo uploaded successfully",
                            Toast.LENGTH_LONG).show();
                }
            });
            uploadRequest.executeAsync();

I googled around for hours, and this facebook sdk is messed up, i can't seem to find any proper answer, if i use shareDialog facebook provides, i can't share local images, if i dont use share dialog i can't open facebook app, and i don't want to use OpenGraph stories .. Any help would be gravely appreciated.

You can post imade or text into facebook by using facebook SDK wich is explaned here

and to post an image

 private void postImageToWall(String accessToken,byte[] image, String text){       
    Bundle params = new Bundle();

    params.putString(Facebook.TOKEN, accessToken);
        //text with the image
    params.putString("message",text);
    // The byte array is the data of a picture.
    params.putByteArray("picture", image);

    try {
        facebook.request("me/photos", params, "POST");
        uploadSucceed = true;
    } catch (FileNotFoundException fileNotFoundException) {
        showToast(fileNotFoundException.getMessage());
    } catch (MalformedURLException malformedURLException) {
        showToast(malformedURLException.getMessage());
    } catch (IOException ioException) {
        showToast(ioException.getMessage());
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM