Monday, May 23, 2011

GET parameters of Facebook Graph API

Name = metadata
Valid values = [0, non-zero (i.e. both -ve and +ve)]
{
"id": "1050172324",
"name": "Suresh Saggar",
"first_name": "Suresh",
"last_name": "Saggar",
"link": "http://www.facebook.com/saggar",
"username": "saggar",
"gender": "male",
"locale": "en_US",
"metadata": {
"connections": {
  "home": "http://graph.facebook.com/saggar/home",
  "feed": "http://graph.facebook.com/saggar/feed",
  "friends": "http://graph.facebook.com/saggar/friends",
  "family": "http://graph.facebook.com/saggar/family",
  "payments": "http://graph.facebook.com/saggar/payments",
  "activities": "http://graph.facebook.com/saggar/activities",
  "interests": "http://graph.facebook.com/saggar/interests",
  "music": "http://graph.facebook.com/saggar/music",
  "books": "http://graph.facebook.com/saggar/books",
  "movies": "http://graph.facebook.com/saggar/movies",
  "television": "http://graph.facebook.com/saggar/television",
  "games": "http://graph.facebook.com/saggar/games",
  "likes": "http://graph.facebook.com/saggar/likes",
  "posts": "http://graph.facebook.com/saggar/posts",
  "tagged": "http://graph.facebook.com/saggar/tagged",
  "statuses": "http://graph.facebook.com/saggar/statuses",
  "links": "http://graph.facebook.com/saggar/links",
  "notes": "http://graph.facebook.com/saggar/notes",
  "photos": "http://graph.facebook.com/saggar/photos",
  "albums": "http://graph.facebook.com/saggar/albums",
  "events": "http://graph.facebook.com/saggar/events",
  "groups": "http://graph.facebook.com/saggar/groups",
  "videos": "http://graph.facebook.com/saggar/videos",
  "picture": "http://graph.facebook.com/saggar/picture",
  "inbox": "http://graph.facebook.com/saggar/inbox",
  "outbox": "http://graph.facebook.com/saggar/outbox",
  "updates": "http://graph.facebook.com/saggar/updates",
  "accounts": "http://graph.facebook.com/saggar/accounts",
  "checkins": "http://graph.facebook.com/saggar/checkins",
  "apprequests": "http://graph.facebook.com/saggar/apprequests",
  "friendlists": "http://graph.facebook.com/saggar/friendlists",
  "permissions": "http://graph.facebook.com/saggar/permissions"
},
"fields": [
  {
     "name": "id",
     "description": "The user's Facebook ID. Publicly available. A JSON string."
  },
  {
     "name": "name",
     "description": "The user's full name. Publicly available. A JSON string."
  },
  {
     "name": "first_name",
     "description": "The user's first name. Publicly available. A JSON string."
  },
  {
     "name": "last_name",
     "description": "The user's last name. Publicly available.  A JSON string."
  },
  {
     "name": "gender",
     "description": "The user's gender.  Publicly available. A JSON string."
  },
  {
     "name": "locale",
     "description": "The user's locale. Publicly available. A JSON string containing the ISO Language Code and ISO Country Code."
  },
  {
     "name": "link",
     "description": "The URL of the profile for the user on Facebook. Available to everyone on Facebook. A JSON string containing a valid URL."
  },
  {
     "name": "username",
     "description": "The user's Facebook username. Publicly available. A JSON string."
  },
  {
     "name": "third_party_id",
     "description": "An anonymous, but unique identifier for the user. Available to everyone on Facebook. A JSON string."
  },
  {
     "name": "timezone",
     "description": "The user's timezone offset from UTC. Available only for the current user.  A JSON number."
  },
  {
     "name": "updated_time",
     "description": "The last time the user's profile was updated. Available to everyone on Facebook. A JSON string containing a IETF RFC 3339 datetime."
  },
  {
     "name": "verified",
     "description": "The user's account verification status. Available to everyone on Facebook.  A JSON boolean."
  },
  {
     "name": "about",
     "description": "The blurb that appears under the user's profile picture. Requires `user_about_me` or `friends_about_me permission`. A JSON string."
  },
  {
     "name": "bio",
     "description": "The user's biography. Requires the `user_about_me`. A JSON string."
  },
  {
     "name": "birthday",
     "description": "The user's birthday. Requires `user_birthday` or `friends_birthday permission`. A JSON string."
  },
  {
     "name": "education",
     "description": "A list of the user's education history. Requires `user_education_history` or `friends_education_history` permission. An array of JSON objects containing `school`, `year` and `type` fields."
  },
  {
     "name": "email",
     "description": "The proxied or contact email address granted by the user. Requires `email` permission. A JSON string containing a valid email address."
  },
  {
     "name": "hometown",
     "description": "The user's hometown.  Requires `user_hometown` or `friends_hometown` permission. A JSON object containing `name` and `id`."
  },
  {
     "name": "interested_in",
     "description": "The genders the user is interested in. Requires `user_relationship_details` or `friends_relationship_details`. A JSON array containing JSON strings."
  },
  {
     "name": "location",
     "description": "The user's current location. Requires `user_location` or `friends_location` permission.  A JSON object containing `name` and `id`."
  },
  {
     "name": "political",
     "description": "The user's political view.  Requires `user_religion_politics` or `friends_religion_politics` permission. A JSON string."
  },
  {
     "name": "quotes",
     "description": "The user's favorite quotes. Requires the `user_about_me`. A JSON string."
  },
  {
     "name": "relationship_status",
     "description": "The user's relationship status. Requires `user_relationships` or `friends_relationships` permission. A JSON string."
  },
  {
     "name": "religion",
     "description": "The user's religion. Requires `user_religion_politics` or `friends_religion_politics` permission. A JSON string."
  },
  {
     "name": "significant_other",
     "description": "The user's significant other.  Requires `user_relationship_details` or `friends_relationship_details` permission.  Returns a JSON object containing `name` and `id`."
  },
  {
     "name": "website",
     "description": "The URL of the user's personal website. Requires `user_website` or `friends_website` permission. A JSON string containing a valid URL."
  },
  {
     "name": "work",
     "description": "A list of the user's work history. Requires `user_work_history` or `friends_work_history` permission. An array of JSON objects containing `employer`, `location`, `position`, `start_date` and `end_date` fields."
  }
]
},
"type": "user"
}
Name = fields
Valid values = CSV of valid fields(keys)
Link: http://graph.facebook.com/saggar?fields=name,link
{
"name": "Suresh Saggar",
"link": "http://www.facebook.com/saggar",
"id": "1050172324"
}
If an invalid field name is specified then an OAuthException will be thrown.
{
"error": {
 "type": "Exception",
 "message": "Unknown fields: invalidfield"
}
}
Name = ids
Valid values = CSV of valid IDs. Used to request multiple objects in a single query
Link: http://graph.facebook.com/?ids=saggar
   {
"saggar": {
  "id": "1050172324",
  "name": "Suresh Saggar",
  "first_name": "Suresh",
  "last_name": "Saggar",
  "link": "http://www.facebook.com/saggar",
  "username": "saggar",
  "gender": "male",
  "locale": "en_US"
}
}
· Duplicate IDs of same type (here username) if specified will throw an OAuthException, although not a meaningful one.
{
"error": {
   "type": "OAuthException",
   "message": "(#803) Some of the aliases you requested do not exist: " //<<<< alias missing    
} 
}
This is a bug in Facebook's code as the message doesn't contain the alias.

· Duplicate IDs of mixed type (here username, id) if specified will throw a meaningful OAuthException.
{
 "saggar": {
    "id": "1050172324",
    "name": "Suresh Saggar",
    "first_name": "Suresh",
    "last_name": "Saggar",
    "link": "http://www.facebook.com/saggar",
    "username": "saggar",
    "gender": "male",
    "locale": "en_US"
 }
}
· Besides, a special identifier 'me', which refers to the current user can be used to identify the user who is logged in. So this (https://graph.facebook.com/me?access_token=validAccessToken) will return the active user's profile.
Link: https://graph.facebook.com/me?access_token=validAccessToken&fields=quotes,name,timezone
{
  "quotes": "\"Be Good, Do Good, Be One\".\r\n\r\n\"What one man can do so can another\".",
  "name": "Suresh Saggar",
  "timezone": 5.5,
  "id": "1050172324"
}
But this (https://graph.facebook.com/me) even if you are logged in will report an OAuthException.

   {
   "error": {
      "type": "OAuthException",
      "message": "An active access token must be used to query information about the current user."
   }
}

1 comment:

  1. Hi, Plz can you tell me how can i get current user id,name etc(i.e. the user who has logged into facebook and is on my app now)

    ReplyDelete