Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Small preview when sharing link on Social media Ruby On Rails

I'm working on a site whose front end is in angularjs and backend in ROR , Same ROR API is used in an android app also . Now I have a situation here . I need to share my Web's post on the Social media like facebook , twitter and google plus . And along with the link to the single post there should be a small preview also (a preview of the post which crawls before posting e.g in facebook) .I did it using angular Plugins . But when it comes to Android side , what they share and what displays on Facebook is the Link only . Then i did some R&D and i came to know that it must be done on server side with social media meta tags . I did a little bit but it still no works . I'm stuck on it . Below is what i've done so far .

 def show
  @post = Post.find_by_permalink(params[:id])
    respond_to do |format|
        format.html
        format.js
    end
end

In My views posts/show.html.erb

<!DOCTYPE html>
<html>
<head>
    <title> Shared Question</title>

    <meta property="og:title" content="My Page" />
    <meta property="og:description" content="A description of my page." />
    <meta property="og:image" content="http://www.example.com/images/my_lovely_face.jpg" />
    <!-- etc. -->
</head>
<body>
Here is the body
</body>
</html>

I just need to show a small preview whenever some user share my web post's link on any media

like image 617
Mani Avatar asked Nov 08 '22 17:11

Mani


1 Answers

You are correct, you need to implement special open graph (and other) tags for the customized social sharing functionalities.

Keep in mind that e.g. facebook will cache your page.

So you may try https://developers.facebook.com/tools/debug/ to test your code without caching - the code itself looks fine.

Example Code:

Place this code between <head> and </head> with your other meta tags.

<meta property="og:title" content="Title">
<meta property="og:site_name" content="Name">
<meta property="og:url" content="URL">
<meta property="og:description" content="Description Text">
<meta property="og:type" content="article">

<!--- network Specific --> 
<meta property="fb:app_id" content="AppID">
<meta name="twitter:card" content="app">
<meta name="twitter:site" content="@FernerJohannes">

If you want to target Twitter specifically here are their card-guidelines: https://dev.twitter.com/cards/getting-started

You may also want to checkout: Open Graph validation for HTML5

like image 73
Johannes Ferner Avatar answered Nov 15 '22 05:11

Johannes Ferner