Gabrijel Batista
Gabrijel Batista

Reputation: 51

Laravel, share image from server to Facebook

I have images saved in storage and I want to share them on Facebook. Sharing is working but not the way I tought it would. I will post examples below to show what I get and what I want.

So I get black post that needs to be clicked on to see image, like this:

What I get:

And I want it to be like this:

What I want:

HTML:

<button onclick="fb()">Facebook</button>
<img src="storage/images/lang/myImage.png" id="imgfb" style="display:none"/>

JavaScript:

<script>

function fb(){
            var imgsrc=document.getElementById("imgfb").src;
          var fbpopup = window.open("https://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(imgsrc), "pop", "width=600, height=400, scrollbars=no");
          return false;
}

</script>

Upvotes: 2

Views: 2206

Answers (1)

Mitsuo Suwa
Mitsuo Suwa

Reputation: 41

You need to set organic tag for image on that link.

On head section of html

    <meta property="og:image" content="{{asset('YOUR-IMAGE-LOCATION')}}" />

The are also other meta tags available for title and description, do check them on https://developers.facebook.com/docs/sharing/webmasters/

Upvotes: 3

Related Questions