How can I know if a node returned from Facebook Graph API is a profile or a page?

I one part of a site I'm programming, users can add facebook pages to a list manually by manually entering the username or id of each page. Once submitted, I connect to Facebook graph API to check that all provided ids or usernames are valid.

I can only accept facebook pages, not profiles.

Graph API used to return a field telling the type of each node returned (user, page, application...) but they don't provide that anymore.

Here is an example output from a page id (/{node-id})

{
  "about": "http://www.365juegos.com", 
  "can_post": true, 
  "category": "Entertainment website", 
  "is_published": true, 
  "new_like_count": 1, 
  "offer_eligible": true, 
  "promotion_eligible": true, 
  "talking_about_count": 1, 
  "unread_message_count": 0, 
  "unread_notif_count": 3, 
  "unseen_message_count": 0, 
  "username": "365juegos", 
  "website": "http://www.365juegos.com", 
  "were_here_count": 0, 
  "id": "415033875603", 
  "name": "365 juegos", 
  "link": "https://www.facebook.com/365juegos", 
  "likes": 1289, 
  "cover": {
    "cover_id": "10151386385585604", 
    "source": "https://scontent-a.xx.fbcdn.net/hphotos-prn1/t1/s720x720/64727_10151386385585604_2060575120_n.jpg", 
    "offset_y": 0, 
    "offset_x": 0
  }
}

And this is one from a profile id (/{node-id}):

{
  "id": "1013953243", 
  "name": "Nilo Vélez", 
  "first_name": "Nilo", 
  "last_name": "Vélez", 
  "link": "https://www.facebook.com/nilovelez", 
  "gender": "male", 
  "timezone": 1, 
  "locale": "en_US", 
  "verified": true, 
  "updated_time": "2014-03-08T22:04:45+0000", 
  "username": "nilovelez"
}

First I looked for the presence of the likes filed, as it is exclusive to pages, but it is not returned if the like count y zero.

Some other fields like *first_name* or locale are exclusive to profiles, but I'm not sure if they will always be present or if users will be able to hide them on a near future.

Any ideas for a simple way to tell pages apart from profiles?

Answers


The type of an object usually comes under meta data and is not returned with a request unless you specify. In order to make a request for the type of the object, simple add ?metadata=1 at the end of your request. Something like:

http://graph.facebook.com/{object_id}?metadata=1

For example, the request:

http://graph.facebook.com/1013953243?metadata=1

will return the following data:

{
   "id": "1013953243",
   "name": "Nilo V\u00e9lez",
   "first_name": "Nilo",
   "last_name": "V\u00e9lez",
   "gender": "male",
   "locale": "en_US",
   "username": "nilovelez",
   "metadata": {
      "connections": XXX
       .
       .
       .
       .
       .
       .
      "type": "user"
   }
}

Need Your Help

Algorithm to find k smallest numbers in array of n items

arrays algorithm selection

I'm trying to write an algorithm which can print the k smallest numbers in an n-size-array in O(n) time, but I cannot reduce the time complexity to n. How can I do this?

How to call remote EJB from standalone client

web-applications java-ee

I have my EJB deployed on weblogic server. I want to access those EJB from standalone applications (a thin client).