Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

facebook - Trouble with <fb:like> page title, like count, and page url

I have a set of pages in my site that are using the FBML method of inserting a FB Recommend button. My problem is that every page on my site shows the exact same recommend count ("557 people recommend this page" even though I just installed the button), and when I've tried to Recommend it myself, it shows up in my news feed with the wrong page title, the wrong URL, and of course, every recommend button on the site is incremented. Here is my code:

og tags (I replaced these with anonymous values to protect my client from looking like they have an idiot developer) ;) :

    <meta property="og:title" content="XXX page title"/>
    <meta property="og:type" content="movie"/>
    <meta property="og:url" content="http://abc.xyz.com/path/to/my/page/"/>
    <meta property="og:site_name" content="XXX site name"/>
    <meta property="fb:admins" content="xxx my facebook id"/>
    <meta property="og:description" content="xxx short description"/>

...then just inside the body:

<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : 'xxxxx',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

...and then later on in the page (the only reason I'm using the FBML method is so I can track the recommend events in google analytics -- this should be unrelated, but for the purposes of full disclosure, I'm including that code here too)...

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
        <script type="text/javascript">
            FB.Event.subscribe('edge.create', function(href, widget) {
                _gaq.push(['_trackEvent', '<?php echo $item->type ?>', 'Facebook Recommend', '<?php echo $item->title ?>']);
            });
        </script>
<!-- FB LIKE BUTTON INSERTED HERE -->
        <fb:like href="<?php echo urlencode('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] )?>" show_faces="false" width="450" action="recommend" font="arial" colorscheme="dark"></fb:like>

The link that shows up in my feed is http://abc.xyz.com/path/to/my/ (the last segment of the URL is missing), and the title is an old one; I realized that all the pages had the same title when I was setting this up, and so I gave them different titles since. I have run several of my URLs through the URL linter and there are no errors, and all the data looks correct.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here are two notes:

  1. Since you checked several URLS using the URL Linter and the result came up as expected this means it's a caching problem, read this.
  2. If you are not using Facebook Graph API...or any Facebook related services other than the Like Plugin, then the first Facebook Javascript initialization snippet is not needed but if it's used then (<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>) is not needed.

EDIT:
Based on the comments, some of the pages have more than 50 likes this means you can't change the title anymore:

You can update the attributes of your page by updating your page's tags. Note that og:title and og:type are only editable initially - after your page receives 50 likes the title becomes fixed, and after your page receives 10,000 likes the type becomes fixed. These properties are fixed to avoid surprising users who have liked the page already. Changing the title or type tags after these limits are reached does nothing, your page retains the original title and type.

source [Editing Meta Tags].

BUT if you really need to change the title and you are okay of probably losing the likes' count, then you can add a fake parameter to the end of the URL meta tag so that Facebook thinks it's a new page:

http://www.domain.com/page.php?123

Please note that I've never used this technique with the new Like Plugin.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...