What have you found for these years?

2011-08-28

Facebook Graph API and the "connections" (media?) :P

Here's the background.

Nick was talking about this in rubyconf.tw/2011:

CRUD Is Not REST - Hypermedia For Y'All

And his works remind me semantic web, RDF, ontology, and other
related or similar things. Then we discussed about Facebook Graph
API, and I promised to show him some demonstration. Too bad we
don't have 3G, nor the access to any wifi at dinner, and I needed to
go back with others to make sure that I can really get back...

So I promised to send him messages about this. Here it is.

At first I was writing this in email, but I guess it's not too bad to
have this in public in case that maybe someone is interested.

You can first check out my user info:
http://graph.facebook.com/spellbook

It would shows:

{
   "id": "1072460044",
   "name": "Lin Jen-Shin",
   "first_name": "Lin",
   "last_name": "Jen-Shin",
   "link": "https://www.facebook.com/spellbook",
   "username": "spellbook",
   "gender": "male",
   "locale": "en_US"
}
Ok, let's start passing metadata=1:
http://graph.facebook.com/spellbook?metadata=1

As you can see, there's:
   "metadata": {
      "connections": {
         "home": "http://graph.facebook.com/spellbook/home",
         "feed": "http://graph.facebook.com/spellbook/feed",
...
Too long, I won't paste all results here.
The problem is that you'll need an access_token to access
those connections (or media? :P)

You can play with facebook's Graph API explorer:
https://developers.facebook.com/tools/explorer
To get an access_token there, and pass access_token=...
in query string to use that access_token.

So I am accessing my "likes" via:
https://graph.facebook.com/spellbook/likes?access_token=...
Note that you'll need to use HTTPS to pass access_token.
And you might see something similar to this:
{
  "data": [
    {
      "name": "Pic Collage",
      "category": "Camera/photo",
      "id": "148811321860660",
      "created_time": "2011-07-17T01:45:42+0000"
    }, 
...
Here we'll get another graph object ID: 148811321860660
Try to access it via:
http://graph.facebook.com/148811321860660
You'll get the info:
{
   "id": "148811321860660",
   "name": "Pic Collage",
   "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/277163_148811321860660_3451369_s.jpg",
   "link": "https://www.facebook.com/piccollage",
   "likes": 559,
   "category": "Camera/photo",
   "website": "http://pic-collage.com",
   "username": "piccollage",
   "description": "From http://cardinalblue.com",
   "parking": {
      "street": 0,
      "lot": 0,
      "valet": 0
   },
...
And it has connections as well:
http://graph.facebook.com/148811321860660?metadata=1
   "metadata": {
      "connections": {
         "feed": "http://graph.facebook.com/148811321860660/feed",
         "posts": "http://graph.facebook.com/148811321860660/posts",
...
Again, you'll need an access token for accessing connections.
Let's try to access:
https://graph.facebook.com/148811321860660/posts?access_token=...
You'll also get the posts for that particular Facebook Page.
So this is not only for users, but also for any other graph objects.
Yet again, you'll see comments/posts also have IDs!
{
  "data": [
    {
      "id": "148811321860660_151516334934765",
      "from": {
        "name": "Pic Collage",
        "category": "Camera/photo",
        "id": "148811321860660"
      },
...
Comments/posts have connections as well!
http://graph.facebook.com/148811321860660_151516334934765?metadata=1
   "metadata": {
      "connections": {
         "likes": "http://graph.facebook.com/148811321860660_151516334934765/likes",
         "comments": "http://graph.facebook.com/148811321860660_151516334934765/comments"
      }

I personally hate Facebook and their API servers, and their old not-REST
at all REST APIs. But to be honest, Facebook Graph API is really cool.

If I don't get it wrong, the guys who designed this previously were
working on GMail and FriendFeed. Facebook bought the right company!

But frankly, the API servers are so unstable and the JSON it returns
changes very often. They don't have a good error code/message
returns when there's something wrong in the API call neither.
It's just good in design, but so badly implemented...

Let me know what do you think, Nick, thank you!

1 retries:

Anonymous said...

test

Post a Comment

All texts are licensed under CC Attribution 3.0