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
2
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.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
You can set a custom image for you website to be shown in fb posts –
You can try reading this for more insight.
Hopefully this helps.