Getting started w/ Facebook API (FQL)

Alex Egg,

This is a quick start guide to get you up and running w/ FQL part of the Facebook API.

Say for example: We want to get all the videos of a user (myself in this case) - we first need to get the user’s permission to access their information. Facebook handles authentication via the oath protocol. The flow would like this:

  1. User clicks link to install your app and clicks yes
  2. Response sends oath token so you can access their data.

Before anything else you need to first register you app and get it’s app id.

Get OAuth Token

Now for step #1 in the flow send the user the below link - it’s the standard FB app yes/no page we’ve all seen:

https://www.facebook.com/dialog/oauth?
    client_id=164837516907837&
    type=user_agent&
    scope=email,read_stream,user_videos,friends_videos,user_about_me,offline_access&
    redirect_uri=http://www.facebook.com/connect/login_success.html

After the user clicks OK they are redirect to the redirect_url and the oath toaken is in the response URL.

https://www.facebook.com/connect/login_success.html#access_token=1364837516907837%7C2.g6_akCDY7umr94sKl4_M1w__.3600.1303063200.1-674426473%7CY2KQmx-VlKvcxPX0WX0SOx6OpP8&expires_in=5079

After this you’ll get your oath token!!!

access_token=1364837516907837%7C2.g6_akCDY7umr94sKl4_M1w__.3600.1303063200.1-674426473%7CY2KQmx-VlKvcxPX0WX0SOx6OpP8

Query API

Now you can query that user’s graph:

https://graph.facebook.com/me?access_token=1364837516907837|2.g6_akCDY7umr94sKl4_M1w__.3600.1303063200.1-674426473|Y2KQmx-VlKvcxPX0WX0SOx6OpP8

and use FQL queries

https://api.facebook.com/method/fql.query?query=SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner=13772156826&access_token=164837516907837|2.2gdLzMH6jVTBP2g8sr604g__.3600.1302642000-674426473|c5sHb3xK-zCvdmdOb2vzeiov7Yo

That will get all videos of given user in XML.


 

Permalink: getting-started-w-facebook-api

Tags: facebook api social graph fql

Last edited by Alex Egg, 2011-06-10 15:54:48
View Revision History