For my web app, I need to get a preview of URL given by the user.
For example, in Facebook, if the user copy-paste an URL,it automatically fetches the content of the URL and displays a preview of the page.
How does it work? Is it a feature of Ajax? I need to do it in Django.
Any tutorials or demos?
For Facebook, there is a standard way to make your site "preview" compatible, using open graph tags. The most common ones are:
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
The complete list is available at the open graph protocol site. You can use PyOpenGraph to parse a URL for its open graph tags. Here is the example from the readme:
>>> import PyOpenGraph
>>> og = PyOpenGraph('http://www.rottentomatoes.com/m/10011268-oceans/')
>>> print og.metadata
{'url': 'http://www.rottentomatoes.com/m/10011268-oceans/',
'site_name': 'Rotten Tomatoes',
'image': 'http://images.rottentomatoes.com/images/movie/custom/68/10011268.jpg',
'type': 'movie',
'title': 'Oceans'}
>>> print og.metadata['title']
Oceans
Related
I don't know why Facebook Share not getting value of og:image, og:title of my website while I inspect element I see everything correct.
This is facebook debug:
Attributes are inferred: The og:image attribute must be explicitly provided, even if it is possible to derive value from other tags.
Lack of assets
The following required assets are missing: og:url, og:type, og:title, og:image, og:description, fb:app_id.
Bad response code
URL returned a bad response response code
These are elements on my website
<meta property="og:url" content="http://vnlovepet.com/blog/huan-luyen-cho-alaska-nhu-the-nao-cho-dung-58">
<meta property="og:type" content="article" />
<meta property="og:title" content="Huấn luyện chó Alaska như thế nào cho đúng?">
<meta property="og:description" content="Huấn luyện chó Alasla là một trong những sở thích của nhiều người, nhưng họ lại chưa biết cách huấn luyện thế nào cho đúng.">
Have a look, how exactly Facebook's scraper sees your URL: https://developers.facebook.com/tools/debug/echo/?q=http%3A%2F%2Fvnlovepet.com%2Fblog%2Fhuan-luyen-cho-alaska-nhu-the-nao-cho-dung-58
There are errors dumped into HTML and that's the reason of your issue.
I am trying to use the Facebook Like Button at its maximum. I am a webmaster in charge of many websites. I read a lot of answers and question, but I still reach the problem. When somebody use the like button on my Website, and let a comment, it will not publish to its profile.
First I tried to use the simple way:
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/fr_FR/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
<div id="fb-root"></div>
<div class="fb-like" data-href="http://www.example.com" data-width="100" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
I have the common message in debug "Invalid App Id: Must be a number or numeric string representing the application id.", because I did not use an app_id.
I setup the OpenGraph meta and crawl them with Facebook debug, OK, no error. I use the Domain insight on this domain to get a fb:admins.
<meta property="og:site_name" content="IT IS IT" />
<meta property="og:title" content="Name of page" />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://www.example.com/" />
<meta property="og:description" content="blablab" />
<meta property="fb:admins" content="10000000xxxxxx" />
<meta property="og:image" content="http://www.example.com/og-image-fb.jpg?v=14170000000" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="1800" />
<meta property="og:image:height" content="945" />
<meta property="og:locale" content="fr_FR" />
And using also in HTML declaration:
prefix="og: http://ogp.me/ns# fb: http://www.facebook.com/2008/fbml"
In a very few websites, I get the feed published on the wall. But on all the others, I get nothing.
After that, I tried to make a WWW Facebook App per website, using "Information" for the type of the app (Using the App_id in OpenGraph meta + the load of the FB SDK, in addition of my fb:admins). It was working well, except I need to create 1 App for 1 site, because on every feed, it will sho MrX like a link on "Name of my App", linked to the url of the website, so I can not use a general app for all my websites.
But after 5 App, Facebook hang my account.... So I am opening a new FB personnal account at my name (I don't want to use FB for anything else then this work), so I am able to provide an ID if they block my account again.
My first question: Is creating 1 app for 1 website is a normal and legal way for Facebook ?
My second question: No way to publish on wall without app_id ? It works on 2 website I have, without it, so I am a little confused ...
Thanks !
Usually, Facebook blocks an account for a very good reason. So you must have done something wrong, usually you do get a reason why they blocked it. Take a look if you can appeal and if there is more information in here: https://developers.facebook.com/appeal
In general, 1 app for 1 Website/Domain is normal and you should ALWAYS use an App ID. Facebook decides about publishing it into the stream of user friends, you can´t really "force" this. It depends on many factors (popularity of the website, spam reports, ...). It will most likely get posted if the user adds a comment though - but of course you can´t force that.
TL;DR, the direct answers to your questions:
Yes.
You should ALWAYS use an App. It may work without one, but it´s not recommended.
How can I use the built in Read Type as a view OG for a non news site.
My pages are defined by a custom object type that is not an Article.
Will this mean that I can add one more type og:type 'article' ?
To make it more clear lets say Slideshare defines a custom OG type of
<meta name="og_type" property="og:type" class="fb_og_meta" content="slideshare:presentation" />
<meta name="og_url" property="og:url" class="fb_og_meta" content="http://www.slideshare.net/ChristinUpshaw/learn-to-knit" />
<meta name="og_image" property="og:image" class="fb_og_meta" content="http://image.slidesharecdn.com/learntoknit2-121024175526-phpapp02/95/slide-1-1024.jpg" />
<!-- SL:start:notranslate -->
<meta name="og_title" property="og:title" class="fb_og_meta" content="Learn to Knit!" />
<meta name="og_description" property="og:description" class="fb_og_meta" content="Learn to knit with these resources. All images found via Flickr Creative Commons search!" />
Now if slideshare wants to publish a read OG, should they create a new og:type ‘article’ in the same page?
Will Facebook allow for 2 og:type's in the same page?
How can I go about publishing views now that Facebook does not allow custom Reads anymore?
It's not possible to have more than 1 og:type. As described in the documentation it's only possible to refer the built-in "read"-action to an "article" og-type:
For developers building apps in the News vertical, we have created the
built-in Read action that can only refer to the built-in Article
object type (Source)
So, what you can do, to achieve this: Build an alternate view/url for your pages, which have the correct og:type "article" set up. Have a look at the Request Header/User Agent. If the term "facebook" isn't provided in the user agent, directly redirect the user to your main page. If "facebook" is part of the user agent, provide the alternate meta-tags on a blank page.
Need help understanding how opengraph works and how it relates to the "FB Like" button.
We do have opengraph meta tags deployed on all of the pages for our content. However
it looks like the only way to get "FB Like" button to work, is to run the URL thru the facebook linter.
If a user attempts to "Like" the page, that was never liked before, only the URL will be posted to the wall.
If the url is ran thru the linter, all the consecutive likes will work properly, by image, title and description will be pulled.
is it possible that the app_id is not linking properly with the pages?
having our FB Admin go and like all the content that is produced is not an option
http://www.nydailynews.com/life-style/travel/underwater-photos-amazing-shots-sea-gallery-1.1078782
<meta property="fb:app_id" content="366487756153">
<meta property="fb:admins" content="1594068001">
<meta property="og:site_name" content="NY Daily News">
<meta property="og:title" content="Mark Tipple's Underwater Project - Underwater photos: Amazing shots from under the sea">
<meta property="og:type" content="article">
<meta property="og:url" content="http://www.nydailynews.com/life-style/travel/underwater-photos-amazing-shots-sea-gallery-1.1078782">
<meta property="og:image" content="http://assets.nydailynews.com/polopoly_fs/1.1078770!/img/httpImage/image.jpg_gen/derivatives/searchthumbnail_75/image.jpg">
<meta property="og:description" content="Talented underwater photographer Mark Tipple, from Sydney, Australia, lies in wait for unsuspecting swimmers and surfers before snapping a perfect picture of them from beneath the waves.">
http://www.nydailynews.com/gossip/john-travolta-experienced-bed-passionate-hotel-romp-claims-masseur-luis-gonzalez-article-1.1079272
<meta property="fb:app_id" content="366487756153">
<meta property="fb:admins" content="1594068001">
<meta property="og:site_name" content="NY Daily News">
<meta property="og:title" content="John Travolta was 'a great kisser' and ‘very experienced’ in bed during passionate hotel romp, claims masseur Luis Gonzalez ">
<meta property="og:type" content="article">
<meta property="og:url" content="http://www.nydailynews.com/gossip/john-travolta-experienced-bed-passionate-hotel-romp-claims-masseur-luis-gonzalez-article-1.1079272">
<meta property="og:image" content="http://assets.nydailynews.com/polopoly_fs/1.1079279!/img/httpImage/image.jpg_gen/derivatives/searchthumbnail_75/image.jpg">
<meta property="og:description" content="Another hotel masseur is claiming sexual shenanigans on the part of John Travolta -- only this accuser says he welcomed the actor's horny horseplay and found him "very experienced" in bed.">
In order to get your page recognized as a custom open graph object you'll need to follow these steps.
Create a facebook app
Setup site domain, namespace etc...
Create a custom action and a custom object under app settings >> Open Graph: Getting Started (see this link for help)
After creating it, you'll see your object under object types in Open Graph Settings
Click on "Get Code" button to get the html tags
Update your page to show up the same html head & meta tags
Go to http://developers.facebook.com/tools/debug to test if you have setup everything right
P.S. Don't forget to hit correct answer if it works, or PM me for more help
Your URL isn't set to the application as noted in the linter,
Object at URL 'http://www.nydailynews.com/life-style/travel/underwater-photos-amazing-shots-sea-gallery-1.1078782' of type 'article' is invalid because the domain 'www.nydailynews.com' is not allowed for the specified application id '366487756153'. You can verify your configured 'App Domain' at https://developers.facebook.com/apps/366487756153.
Add the proper domain to your settings and it should work.
Having never dealt with Facebook at a developer level, I'm sure that I'm doing something very obviously wrong here. Anyway, here's the problem:
I generate the like button code from https://developers.facebook.com/docs/reference/plugins/like/ and then copy it into my page. When I try to view the site I get nothing displaying.
I noticed that the url in the script section fails to include the protocol (it comes out with: "//connect.facebook.net/en_US/all.js#appId=207642302633270&xfbml=1"). When I have a look what's happening using Firebug I can see that it's inserting the script tag into the head section - but the URL doesn't work. I've tried modifying it to include "https:" as the protocol and I then see that the script gets loaded and that also it inserts a bunch of CSS into the head section.
But still nothing displays on the site.
The only thing I can think of that could be problematic is that I (or, more specifically, my client) doesn't have a Facebook company profile of any sort - I can ask them to set one up if required but this would not be the preferred option as they don't want to maintain a Facebook profile for the business.
Here's a stripped down sample I'm working with:
<html>
<head>
<title>Testing the Like Button</title>
<meta property="og:title" content="Company FB Test" />
<meta property="og:type" content="company" />
<meta property="og:url" content="http://www.domain.com/fb-test.html" />
<meta property="og:image" content="http://www.domain.com/logo.png" />
<meta property="og:site_name" content="Site Name" />
<meta property="fb:admins" content="__MY_FB_ID__" />
</head>
<body>
<script>(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "https://connect.facebook.net/en_US/all.js#appId=207642302633270&xfbml=1";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));</script>
<div class="fb-like" data-send="false" data-layout="box_count" data-width="67" data-show-faces="false" data-font="arial"></div>
</body>
</html>
A couple of notes:
The sample includes the protocol "https:" - as mentioned, I've tried without as well.
This has been tested in the latest versions of Chrome 13, Firefox 6 and IE 9
I've tested this in Facebook Lint and it gives me no errors.
Thanks in advance to whoever succeeds in pointing out the obvious to me - and to anyone else who chimes in with any friendly advice.
Cheers,
Zac
You need to make sure to add this code somewhere in your page:
<div id="fb-root"></div>
You will see in the chrome debugger tool that there is an error saying it can't find that div.