Graph APIを利用することで、Facebookのさまざまなオブジェクトへアクセスできます。
| Connections | URL |
|---|---|
| Friends | https://graph.facebook.com/ID/friends?access_token=... |
| News feed ※outdated | https://graph.facebook.com/ID/home?access_token=... |
| Profile feed (Wall) | https://graph.facebook.com/ID/feed?access_token=... |
| Status | https://graph.facebook.com/ID/statuses?access_token=... |
| Likes | https://graph.facebook.com/ID/likes?access_token=... |
| Movies | https://graph.facebook.com/ID/movies?access_token=... |
| Music | https://graph.facebook.com/ID/music?access_token=... |
| Books | https://graph.facebook.com/ID/books?access_token=... |
| Notes | https://graph.facebook.com/ID/notes?access_token=... |
| Permissions | https://graph.facebook.com/ID/permissions?access_token=... |
| Photo Tags | https://graph.facebook.com/ID/photos?access_token=... |
| Photo Albums | https://graph.facebook.com/ID/albums?access_token=... |
| Video Tags | https://graph.facebook.com/ID/videos?access_token=... |
| Video Uploads | https://graph.facebook.com/ID/videos/uploaded?access_token=... |
| Events | https://graph.facebook.com/ID/events?access_token=... |
| Groups | https://graph.facebook.com/ID/groups?access_token=... |
| Checkins | https://graph.facebook.com/ID/checkins?access_token=... |
| Objects with Location | https://graph.facebook.com/ID/locations?access_token=... |
| URL | 対象ユーザー |
|---|---|
https://graph.facebook.com/me/ |
認可ユーザー |
https://graph.facebook.com/ID/ |
IDで指定したユーザー |
https://graph.facebook.com/username/ |
ユーザーネームで指定したユーザー |
ユーザーに関するすべてのGraph APIへは、このURLを基本にアクセスします。またこの基本URLへアクセスしたときには、そのユーザーのプロパティが返されます。たとえばFacebook Platformのプロパティは、
| https://graph.facebook.com/19292868552 | (IDで指定) |
| https://graph.facebook.com/platform | (ユーザーネームで指定) |
で取得できます。その内容は、
{
"id" : "19292868552",
"name" : "Facebook Platform",
"picture" : "http://profile.ak.fbcdn.net/hprofile-ak-ash2/276791_19292868552_1958181823_s.jpg",
"link" : "http://www.facebook.com/platform",
"likes" : 4801185,
"cover" : {
"cover_id" : "10150835335278553",
"source" : "http://a6.sphotos.ak.fbcdn.net/hphotos-ak-ash3/s720x720/547890_10150835335278553_344659408_n.jpg",
"offset_y" : 32
},
"category" : "Product/service",
"is_published" : true,
"website" : "http://developers.facebook.com",
"username" : "platform",
"founded" : "2007",
"company_overview" : "Facebook Platform enables anyone to build social apps on Facebook and the web.",
"mission" : "To make the web more open and social.",
"about" : "We're building the social web. Get the latest here: developers.facebook.com ",
"were_here_count" : 1,
"talking_about_count" : 18760
}
のようなものです。User | Facebook Developers
ユーザーネームは、ユーザーのページURL「http://www.facebook.com/username」で使用されている文字列です。これは初期状態では存在せず、ユーザーネーム (ユニークURL) で取得できます。Facebookページのユーザーネーム(ユニークURL)の設定方法
ユーザーネーム (username) とネーム (name) は異なります。ユーザーネームはユーザーを識別する一意の名前であり、ユーザーページのURLに使用されます。一方でネームはただの表示上の名前であり、任意の名前を設定できます。
ユーザーネーム (username)
自分のプロフィールページ(http://www.facebook.com/●●●)の「●●●」の文字のことです。ユーザーネームは一度だけ変更できます。ただし、すでに他のユーザーが使用している場合は、そのユーザーネームは取得できません。
ユーザーネームとは - Facebook navi[フェイスブックナビ]
<img src="https://graph.facebook.com/ID/picture" />
| 値 | 幅 [pixel] | 高さ [pixel] |
|---|---|---|
| square | 50 | 50 |
| small | 50 | 可変 |
| normal | 100 | 可変 |
| large | 200 | 可変 |
http://graph.facebook.com/platform/picture?type=large のようにアクセスすると、実際に画像があるURLへリダイレクトされます。
取得結果をフィルタするには、次の3つの形式があります。
そしてそれぞれにlimitで、取得数の上限を指定できます。Pagination | Facebook Developers
※1 時間は、UNIX時間で指定します。2012/1/1 00:00:00より新しいデータを、上限数25で取得する場合を考えます。
このとき2012/1/1 00:00:00がUNIX時間で1325343600であることから、
https://graph.facebook.com/me/feed?since=1325343600&limit=25
となります。
2012年の1月の、1か月間に投稿されたデータを取得する場合を考えます。
2012年の1月は2011/12/31 23:59:59より後で、2012/2/1 00:00:00より前と表せます。そしてそれぞれのUNIX時間が1325343599と1328022000であることから、
https://graph.facebook.com/me/feed?
since=1325343599&until=1328022000
となります。
期間は「since~until」の時間で指定するため、パラメータの値はつねに「since < until」の関係となります。
これと同一の指定をField Expansionでするならば、
https://graph.facebook.com/me
?fields=feed.since(1325343599).until(1328022000)
とします。
複数のGraph APIの呼び出しを一括して行えます。Field Expansion | Facebook Developers
GET https://graph.facebook.com/ID?fields=FIELD_NAME1,FIELD_NAME2
たとえばログインユーザーのnameとbirthdayを取得するには、
https://graph.facebook.com/me?fields=name,birthday
とします。
feedのmessageとcommentsフィールドのみを取得するには、
https://graph.facebook.com/me?
fields=feed.fields(message,comments)
とし、feedのmessageとcommentsフィールドのみを2件取得するには、
https://graph.facebook.com/me?
fields=feed.limit(2).fields(message,comments)
とします。または、
https://graph.facebook.com/me?
fields=feed.fields(message,comments).limit(2)
のように順序を入れ替えても意味は同じです。
たとえば、
https://graph.facebook.com/me?fields=home,feed
としてニュースフィードとウォールの情報を一括して取得したときは、
{
"id" : "0000",
"home" :
{
"data" : [
{
...
}
],
"paging" :
{
"previous" : "https://graph.facebook.com/0000/home?limit=25&since=...",
"next" : "https://graph.facebook.com/0000/home?limit=25&until=..."
}
},
"feed" :
{
"data" : [
{
...
}
],
"paging" :
{
"previous" : "https://graph.facebook.com/0000/feed?limit=25&since=...",
"next" : "https://graph.facebook.com/0000/feed?limit=25&until=..."
}
}
}
のように2つのデータが連結された形式で返されます。