SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    External Site: Show content if page is liked problem

    So what I'm trying to do is get the content in <div id=content> to show if the page has been "liked". I got it to work if the user has just pressed the like button, but if the page refreshes, or the user comes back at a later time, it remembers that the user likes the page (of course), but it does not show the content in <div if=content> unless the user unlikes and then likes the page again. Im guessing this is because what the code is referencing is some sort of click event, rather than if the page is liked or not.

    Here is the link:

    jackthe7th.dyndns.org/test

    Here is the code:

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml"
    		 xmlns:og="http://ogp.me/ns#"
          xmlns:fb="http://www.facebook.com/2008/fbml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>WD Fan Page</title>
    <meta property="og:title" content="WD Fan Page"/>
    <meta property="og:type" content="company"/>
    <meta property="og:url" content="jackthe7th.dyndns.org/test"/>
    <meta property="og:site_name" content="WD Fan Page"/>
    <meta property="fb:admins" content="560504907"/>
    <meta property="og:description"
    content=" fan page Like"/>
    <script type="text/javascript" src="jquery.js"></script>
    <style type="text/css">
    #content { 
    display: none;
    padding: 20px 0 0 0;
    }
    </style> 
      </head>
      <body>
        <h1>WD Fan Page</h1>
    <div id="fb-root"></div>
    <p><fb:login-button autologoutlink="true"></fb:login-button></p>
    <p><fb:like></fb:like></p>
    
    <script>
    window.fbAsyncInit = function() {
    FB.init({appId: '205453252832209',
    status: true, 
    cookie: true,
    xfbml: true});
     
     FB.Event.subscribe('auth.login', function() {
                window.location.reload();
            });
    
    FB.Event.subscribe('edge.create', function(href, widget) {
    jQuery('#content').show();
    });
    FB.Event.subscribe('edge.remove', function(href, widget) {
    jQuery('#content').hide();
    });
    };
    (function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol +
    '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
    
    }());
    </script>
    
    <div id="content"> This content shows up when user likes page <br />
    if you unlike this page it will go away!
    
    </div>
      </body>
     
    </html>

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    edge is an element used to flag a like in real time, not a previous one.

    Basically you would use edge to thank the user for having just liked something via ajax or with an alert.
    - Ted S

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, so how would i do it for a previous one?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    [edited]

    You can parse the Graph API if you get permission from the user. Upside of this is working on specific pages, downside is the permission bit and code involved. I'm not sure if there's a solution that's easier for an entire site; searching around did not yield much on a direct path.

    http://techfreak.me/2011/05/11/how-t...e-on-facebook/

    For an app it's more direct as this is passed right too the page.
    - Ted S


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •