Sharing to Facebook from Android using setContentUrl ()

I am having problems trying to share content with my Facebook app. I use the following code for this:

facebookButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(ShareDialog.canShow(ShareLinkContent.class)){
                ShareLinkContent linkContent=new ShareLinkContent.Builder()
                        .setContentUrl(Uri.parse(imageUrls.get(0)))
                        .build();
                shareDialog.show(linkContent, ShareDialog.Mode.WEB);

            }
        }
    });

      

My images are stored in Firebase storage and I can post to Facebook, but title and description are both set to firebasestorage.googleapis.com like this linked image: screenshot of general post

Note. The setContentDescription () and setContentTitle () and setImageUrl () elements have been deprecated. Is there a way to set the title and description of a shared post?

0


source to share


1 answer


FadyDev, I don't know if you solved your problem, but this is what I am doing instead of the deprecated codes:

// Builds the object    
   ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("fb:app_id", my_app_ID)
            .putString("og:url", link_to_site)
            .putString("og:type", objectType)
            .putString("og:title", contentTitle)
            .putString("og:description", contentDescription)
            .putString("og:image", imageLink)
            .build();

// Builds the action
        ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                .setActionType(actionName)
                .putObject(objectName, object)
                .build();

// Create the openGraphContent
        ShareOpenGraphContent openGraphContent = new ShareOpenGraphContent.Builder()
                .setPreviewPropertyName(objectName)
                .setAction(action)
                .build();

        return openGraphContent;

      

Look in the facebook doc which action you want to use and the corresponding object type and required parameters.



https://developers.facebook.com/docs/sharing/opengraph/using-actions https://developers.facebook.com/docs/reference/opengraph

Hope this helps!

0


source







All Articles