I have added basic Facebook "Like/Share" buttons to a webpage, using code copied directly from the Facebook Developers page. There are 2 parts to the code: a javascript block and a div tag with a class of "fb-like" Heres the javascript:
<div id="fb-root"></div><script>(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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
And here's the div tag for where I want the buttons to appear:
<div class="fb-like" data-href="http://www.bethcake.com" data-width="90" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
Here are the problems I'm encountering:
When the webpage loads, I get 2 javascript warnings. The warnings refer to the connect.facebook.net source code, line 233, not any code I've written. They are:
- Invalid App Id: Must be a number or numeric string representing the application id.
- FB.getLoginStatus() called before calling FB.init().
Also on page load, I get a php error (like.php.1:948):
- Blocked a frame with origin "http://www.facebook.com" from accessing a frame with origin "http://www.bethcake.com". Protocols, domains, and ports must match.
This error is puzzling. First of all, I'm not using frames. Second, the protocols do match and there is nothing here about ports. Of course the domains don't match: I'm not trying to collect "Likes" for a Facebook page; I want to get "Likes" for an external website page. Am I missing something?
I ran the URL through the Facebook Open Graph Object Debugger. It brought up a number of warnings I don't understand. They are:
- fb:admins and fb:app_id tags are missing.
- og:title, og:type, and og:image are missing.
- og:url, go:title, go:description, and go:image properties should be explicitly provided
Okay, fine. But where and how am I supposed to add these? I've looked through the Facebook documentation and searched stackoverflow, without success. If these are supposed to be added to the data-href string in the div tag, please give me an example.
<meta property="og:type" content="website">
This suggests that if I included the fb:app_id meta tag, I'd lose the first javascript warning. As far as I can tell, I'd still get the second warning. Also, I now think what I described as a php error is in fact a javascript error. Oddly enough it shows up in the Safari Web Inspector but not in Google Developer Tools, Opera Dragonfly, or Firebug. – Crapshooter