Search code examples
facebookanimated-giffacebook-sharer

Facebook URL share option, doesn't support gif image while the same option works in giphy.com


Even though exact meta tags are used, the shared url doesn't scrape correctly, the gif isn't shown, while in giphy.com's facebook share option returns the expected result. Is there a some sort of agreement with facebook?


Solution

  • The problem was solved, I was able to share GIF with facebook sharer. For example, the link is the following, https://www.facebook.com/sharer/sharer.php?u=http://example.com/gif. So in my application when facebook's bot tries to enter my link - http://example.com/gif I'm just returning the gif image by WRITING it directly to the output stream. If you return the actual gif url or feed regurl og:image metatags it WILL NOT work. So the secret is to write the gif directly to the output stream. The following is the java code how to handle it:

        @RequestMapping(value = "/gif", method = RequestMethod.GET, produces = "image/gif")
    public void testphoto(HttpServletResponse response) throws IOException {
        URL imageURL = new URL("http://example.com/some_real_gif_url.gif");
        final String formatName = "gif";
        response.setContentType("image/gif");
    
        OutputStream out = response.getOutputStream();
        InputStream in = imageURL.openStream();
    
        byte[] buffer = new byte[1024];
        int count;
    
        while ((count = in.read(buffer)) != -1) {
            out.write(buffer, 0, count);
        }
    
        // Flush out stream, to write any remaining buffered data
        out.flush();
    
    }
    

    If implemented correctly, you will get the same result as giphy share option offer in the following link - https://www.facebook.com/sharer/sharer.php?u=http://gph.is/YeaoHh