Search code examples
javascriptfacebook-group

Display current number of Facebook group members using JavaScript


Is there a way to display the current number of members of my Facebook group on a SquareSpace code block (which only accepts HTML and JavaScript)?


Solution

  • Totally.

    You can use Facebook Graph to accomplish what you want. Using an ordinary HTTPS request, I got this JSON-formatted results :

    {
       "id": "165227436975532",
       "about": "Salon de Th\u00e9 style traditionnelle ..!!",
       "can_post": false,
       "category": "Restaurant/Cafe",
       "category_list": [
          {
             "id": "203462172997785",
             "name": "Tea Room"
          }
       ],
       "checkins": 66,
       "cover": {
          "cover_id": "476669145831358",
          "offset_x": 0,
          "offset_y": 54,
          "source": "https://scontent.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/11536065_476669145831358_6075091507244297763_n.jpg?oh=7c6940ee3f2566884609fc59da224b67&oe=563A1B1D",
          "id": "476669145831358"
       },
       "has_added_app": false,
       "is_community_page": false,
       "is_published": true,
       "likes": 1246,
       "link": "https://www.facebook.com/arabiccafe",
       "location": {
          "city": "Sousse",
          "country": "Tunisia",
          "latitude": 35.864546,
          "longitude": 10.5988045,
          "street": "Hammem Sousse",
          "zip": "4011"
       },
       "name": "Arabica Cafe",
       "parking": {
          "lot": 0,
          "street": 0,
          "valet": 0
       },
       "phone": "21770198",
       "talking_about_count": 6,
       "username": "arabiccafe",
       "were_here_count": 66
    }
    

    In order to get these info, you can use a normal XHR request (or jQuery.ajax if you use jQuery) and make a GET request to this URL :

    https://graph.facebook.com/arabiccafe?access_token={your_token}
    

    You can generate a token following these directives.