开发者

Facebook Like Button Dislikes My Code

开发者 https://www.devze.com 2023-03-17 18:49 出处:网络
I\'ve been trying to implement a Facebook Like button on my blog like this: $(\"#fblike\").append(\" <iframe src=\'http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;\" + wind

I've been trying to implement a Facebook Like button on my blog like this:

$("#fblike").append(" <iframe src='http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;" + window.location.href + "&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=60' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:50px; height:60px;' allowTransparency='true'></iframe>");

And adding this to the <head> of 开发者_开发百科my HTML source file:

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>

The problem is that when I try to test the Like button it shows 1 instead of 0 and a second later goes back to 0. Nothing changed at my Facebook profile neither. What's wrong and how to correct this?

PS: I'm running this on a localhost server, in my case http://nathan-camposs-macbook-pro.local/~Nathan


I think the events go something like:

  1. You click the button.
  2. Javascript sends the like request to FB.
  3. Facebook tries to access your page ("localhost").
  4. It can't access it so the request is denied.

UPDATE:-

I noticed that your src attribute starts: 'http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;" + window.location.href + "&amp;

i think it should be: 'http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;href=" + window.location.href + "&amp;

notice the href=


I've had problems testing the like on sites using temp urls - Facebook doesn't like it when the associated app_id value is not related to the url of the page you're trying to like. But I could be wrong. If you temporarily expand the width to something beyond 50 (like 300-350), there should be an "error" link that pops up that will give you some more valuable information...


If you use fbml then you will not need the application ID. Using fbml you can configure several things. I think you already have a look at-

http://developers.facebook.com/docs/reference/plugins/like/

You can try the following code

<head>
 <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
</head>

Then in the body

<div id="fb-root"></div>
<fb:like href="http://yoururl" send="true" width="450" show_faces="true" font="">
</fb:like>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号