1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

FQL Query to find if member liked page

Discussion in 'FaceBook' started by locknload007, Feb 14, 2011.

  1. locknload007

    locknload007 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 14, 2010
    Messages:
    475
    Likes Received:
    67
    I am looking for a working code to do a query to see if someone has liked a page or not. It seems the code stopped working late last year.

    The code I have is

    PHP:
    $fb_query="SELECT uid FROM page_fan WHERE uid=".$user_id." AND page_id=".$app_id;
    Thanks
     
  2. locknload007

    locknload007 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 14, 2010
    Messages:
    475
    Likes Received:
    67
    I should add, I can get an array of pages liked using opengraph.
     
  3. Website

    Website Supreme Member

    Joined:
    Feb 8, 2008
    Messages:
    1,291
    Likes Received:
    286
    Location:
    whitehouse
    that's gonna go over the heads of 99% of people here
    better consult an expert
     
  4. locknload007

    locknload007 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 14, 2010
    Messages:
    475
    Likes Received:
    67
    Website,

    Aren't you in that 1 percent?

    What I am wanting to do is reward someone for liking my page. I figure I can then reward them for liking more of my pages, and if I want to get real bold, I could reward them for liking a lot of pages.

    I did use http://developers.facebook.com/docs/reference/rest/fql.query to run my query above
    PHP:
    SELECT uid FROM page_fan WHERE uid=xxxxxxxx AND page_id=xxxxxxxx
    adding my id and page id and it did spit out my id.

    So that tells me that other parts of the code is messed up.
     
  5. pyronaut

    pyronaut Executive VIP

    Joined:
    Dec 9, 2008
    Messages:
    1,229
    Likes Received:
    1,422
    • Thanks Thanks x 1
  6. locknload007

    locknload007 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 14, 2010
    Messages:
    475
    Likes Received:
    67
    I had read this on that page

     
  7. pyronaut

    pyronaut Executive VIP

    Joined:
    Dec 9, 2008
    Messages:
    1,229
    Likes Received:
    1,422
    FQL is also being depreciated aswell.

    AFAIK, Everything is being rolled into the new "graph api", but in staggers. Use it while it lasts, when they integrate that API call into the new API, they should put a link up.

    Their sandbox still works on that page (Which just calls their API anyway), so it is definitely still working.
     
    • Thanks Thanks x 1
  8. nesterdwarf

    nesterdwarf Regular Member

    Joined:
    May 30, 2008
    Messages:
    276
    Likes Received:
    539
    Location:
    State of Misery...er, Missouri...
    I'm not sure about the FBML but if you can get the graph of likes, then you should be able to look through and check using PHP.
    Code:
    function checkFan($l,$n, $a){
    	global $facebook;
    	global $isFan;
    	for($i = 0; $i < $n; $i++) {
    		$v = $l['data'][$i]['id'];
    		$m = $a;
    		if ($v == $m){
    			return $isFan = 'true';
    		}else{
    			return $isFan = 'false';
    		}
    	}
    }
    
    Where $l = user_likes (the information you have), $n = total number of likes, and $a is your page id...

    Should work or maybe not...;)

    HTH
    ND
     
    • Thanks Thanks x 1
  9. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Here is some jquery that basically does the same thing as the php above just on the client side (calls the graph and loops through the results while and checking for an id as it progresses through the object).
    Code:
    var page_id = '1234';
    $.getJSON("https://graph.facebook.com/me/likes?callback=?",
    	{
    		access_token: 'xyz123'
    	},
    	function(response) {
    		$.each(response.data, function(i,data){
    			if(response.data[i].id == page_id) alert('You liked ' + page_id);
    			if (i == response.data.length) return false;
    		});
    	}
    );
     
    • Thanks Thanks x 2
  10. locknload007

    locknload007 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 14, 2010
    Messages:
    475
    Likes Received:
    67
    I was able to get this to work, to reward 50 coins if they liked the app page. I am storing if they are a fan or not in a database.

    PHP:
    $user_query=mysql_query("SELECT * FROM ".$user_db." WHERE UserID='$user_id' LIMIT 1");
    $user_result=mysql_fetch_assoc($user_query);

    if(
    $user_result['IsFan']==0)
    {
        
            
    $fb_query='SELECT uid FROM page_fan  WHERE uid='.$user_id.' AND page_id='.$app_id;

      if(
    $fb_query[0]!=null)
      {
        
    mysql_query("UPDATE ".$user_db." SET CurrentPoints=CurrentPoints+'$like_amount',IsFan='1' WHERE UserID='$user_id'");
      }
    }
     
  11. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    hmm I don't think I've seen anything about fql being depreciated, just the old rest api. I believe that fql will still be available through the api read tier even after old rest is gone.
     
  12. Crazy

    Crazy Jr. Executive VIP

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    Depreciated is interchangeable with deprecated. It just means it is being phased out or superseded by an alternative method that is in some form or fashion better than its predecessor.
     
    • Thanks Thanks x 1
  13. locknload007

    locknload007 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 14, 2010
    Messages:
    475
    Likes Received:
    67
    anyone game for setting up an app and give points to those that like certain pages?

    I am close, have started setting up a few more tables, one for pages, one for likes.

    I think I would pull all pages, they click on a page, they then will go to a page.php?id=1 it will check the page id with the likes table, if they did not like it before, a like button will be displayed, it till then give them the coins, and transfer them back to the list of pages.

    Bad thing is that cant give them all that much, so not really worth it for them to be liking pages.
     
  14. pyronaut

    pyronaut Executive VIP

    Joined:
    Dec 9, 2008
    Messages:
    1,229
    Likes Received:
    1,422
    From Wikipedia : Depreciated is often confused or used as a stand-in for "deprecated";

    I use it since most non programmers understand it as "losing value over time". Which I think basically sums it up in software development terms. :)
     
  15. Crazy

    Crazy Jr. Executive VIP

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    Yeah, plus deprecated sounds too close for comfort w/ defecated :|
     
  16. pyronaut

    pyronaut Executive VIP

    Joined:
    Dec 9, 2008
    Messages:
    1,229
    Likes Received:
    1,422
    That's OK, I'm not too worried about it.