Search code examples
facebook-fqlaliasfacebook-group

How to get FB group by alias (FQL)


Does there exist any way to get group by it's alias (username)?

SELECT id, name, pic_big, type, url, username FROM profile WHERE username='somealias'

works for pages, but doesn't works for groups! For groups it returns

(#803) Some of the aliases you requested do not exist: somealias

Solution

  • profile table is like a parent class for user, group, page, event, or application tables. (see https://developers.facebook.com/docs/reference/fql/profile/)

    It has field username but values in this field are filled from related tables, and table group has no field username (see https://developers.facebook.com/docs/reference/fql/group). So when we query profile using where id = someid we get such results:

    SELECT id, name, pic_big, type, url, username FROM profile WHERE id= '195466193802264'
    
    {
      "data": [
        {
          "id": 195466193802264, 
          "name": "Facebook Developers", 
          "pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-default.png", 
          "type": "group", 
          "url": "https://www.facebook.com/groups/195466193802264/", 
          "username": ""
        }
      ]
    }
    

    As you can see, username is empty for group.

    update

    After some investigation I found that groups CAN have usernames. Oficially they can't, but group's email part before @ symbol is it's username.

    When you query the profile if you only specify its username you receive nothing. But if you'll add its name your group will appear.

    Example:

    SELECT id, name, pic_big, type, url, username FROM profile 
      WHERE username = 'rock.mfc' and type = 'group'
    

    will result

    {
      "data": [
      ]
    }
    

    But the query

    SELECT id, name, pic_big, type, url, username FROM profile
      WHERE name = 'ROCK MUSIC FANS CLUB' and username = 'rock.mfc' and type = 'group'
    

    will give the required result:

    {
      "data": [
        {
          "id": 268045023346892, 
          "name": "ROCK MUSIC FANS CLUB", 
          "pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-guitar.png", 
          "type": "group", 
          "url": "https://www.facebook.com/groups/rock.mfc/", 
          "username": "rock.mfc"
        }
      ]
    }
    

    Hope it'll help you.