Faraz Shaikh
Faraz Shaikh

Reputation: 347

How can I share a base64 image to facebook through JavaScript?

I am trying to share base64 image to facebook i have gone with many API, all i found is sharing url ,

imagedata gives me base url code

object gets only url

how can i share my page using this base64 encode image

Here is my code

 #JavaScript

 function ogShare() {
        var canvas = document.querySelector('#screenShotBody > canvas');
        var dataURI = canvas.toDataURL('image/jpeg', 1.0);
        var imgdata = dataURI.match(/data:(image\/.+);base64,(.+)/);

        FB.ui({
            method: 'share_open_graph',
            action_type: 'og.likes',
            action_properties: JSON.stringify({
                object: "https://imgur.com/a/3oGNDZz" //this gets only url
            })
        }, function (response) {
            // Debug response (optional)
            console.log(response);
        });
    }

html

  <div class="modal-body">
            <a data-placement="top" onclick="ogShare();" data- 
      toggle="tooltip" style="cursor:pointer" title="Share"><i class="fas 
     fa-share-alt"></i> <i class="fab fa-facebook-square"></i></a>
            <div class="container-canvas">
                <div id="screenShotBody"></div>
            </div>
        </div>

Upvotes: 3

Views: 1772

Answers (1)

jspcal
jspcal

Reputation: 51914

Not sure if this can be done through FB's API's currently. Another option would be to store the image temporarily on your server and give it a publicly accessible URL or upload it to an image sharing site such as imgur. And then pass that URL to the FB API.

Upvotes: 1

Related Questions