Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

android - Unable to share photo in Facebook

I am taking a photo using an Android phone, and I want to post it in Facebook. My code:

private void SharePhotoFacebook(Bitmap bmp) {
    FacebookSdk.sdkInitialize(FaceActivity.this);
    // Create a callbackManager to handle the login responses.
    callbackManager = CallbackManager.Factory.create();

    shareDialog = new ShareDialog(this);

    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(bmp)
            .build();
    if(ShareDialog.canShow(SharePhotoContent.class)){
        SharePhotoContent content = new SharePhotoContent.Builder()
                .addPhoto(photo)
                .build();
        shareDialog.show(content);
    }

    // this part is optional
    shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {
            Log.i("David", "éxito");
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {
            Log.i("David", "Error");
        }
    });
}

But no dialog is showing, and nothing is posted in Facebook. I have implemented this code in the same Activity I take photo (FaceActivity), and is the Activity declared in Facebook Developer page of the app. What is wrong?

I can see like something tries to show (a grey "flash" that appears in the screen) but nothing shows.

EDIT: Im taking photo this way:

makePhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mCameraSource.takePicture(null, new CameraSource.PictureCallback() {
                @Override
                public void onPictureTaken(@NonNull byte[] bytes) {
                    Log.i("David", String.valueOf(bytes.length));
                    bmp= BitmapFactory.decodeByteArray(bytes,0,bytes.length);
                    ShowShareDialog();
                    //SharePhotoFacebook(bmp);
                }
            });
        }
    });

I just realized I have this in my debug:

Unsupported get request. Object with ID 'XXXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api [extra]: 
question from:https://stackoverflow.com/questions/65881702/unable-to-share-photo-in-facebook

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...