Problem with Facebook like button
I added a standard facebook like button to my webpage:
function CreateNewLikeButton() {
var elem = $(document.createElement("fb:like"));
elem.attr("width", "200");
elem.attr("layout", "standard");
elem.attr("font", "arial");
$("div#fb-root").empty().append(elem);
FB.XFBML.parse($("div#fb-root").get(0));
}
When I click on it i recie开发者_StackOverflow社区ve an error that says that current url is not available.
current url is http://localhost....
what to do ?
You need to have an "href" attribution as well.
function CreateNewLikeButton() {
var elem = $(document.createElement("fb:like"));
elem.attr("width", "200");
elem.attr("layout", "standard");
elem.attr("font", "arial");
elem.attr("href","http://site.com/page.php");
$("div#fb-root").empty().append(elem);
FB.XFBML.parse($("div#fb-root").get(0));
}
You should put opengraph tags in the <head>
section of the page you specified in "href", so you would be able to administrate your comments.
for more information visit facebook developers documentation.
Two issues:
You need to tell Facebook in some fashion what the URL is being "Liked"
Facebook needs to be able to access that URL. If your URL is "localhost" then Facebook won't be able to connect to it. From the Facebook Social Plugin page for the Like Button:
When does Facebook scrape my page?
Facebook needs to scrape your page to know how to display it around the site. Facebook scrapes your page every 24 hours to ensure the properties are up to date. The page is also scraped when an admin for the Open Graph page clicks the Like button and when the URL is entered into the Facebook URL Linter. Facebook observes cache headers on your URLs - it will look at "Expires" and "Cache-Control" in order of preference. However, even if you specify a longer time, Facebook will scrape your page every 24 hours. The user agent of the scraper is: "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
精彩评论