使い方はここを読んでもらうとして、必要なところだけまとめると
IDは全てのオブジェクトに対して一意に決まる数字の識別子。
人やFacebookページへのアクセスに関しては
https://graph.facebook.com/btaylor
IDに名前かページにしてもアクセス可能
例えば、上記のリンクにアクセスすると以下の通り。
id, name, first_name, last_name, link, username, gender, localeが拾える
ちなみにTitaniumでこれを実現するためには
if(!Ti.Facebook.loggedIn) {
Ti.Facebook.authorize();
} else {
処理したいこと
}
でログインしていなければauthorize()メソッドでユーザーに情報許可のダイアログを表示する
https://graph.facebook.com/bgolub?fields=id,name,picture
でqueryを発行した場合にロケーション情報が必要な時はwith=locationパラメーターを追加
https://graph.facebook.com/me/home?with=location
http://graph.facebook.com/100001696601312/picture?type=large
○クエリの結果を制限する
limitで数を、offsetは最新のものから何個目から取得するか、untilは特定日のいつまでか、sinceは特定日のいつからか。それぞれのパラメータはunixtime形式で指定する
unixtimeは1970年1月1日00:00:00を0として表示する秒数
RFC2811は"Wed, 02 May 2012 07:47:33 +0000"という表示
残念ながらTwitterやMixiの時間表示形式は "Wed 02 May 2012 07:47:33 +0000"であり、カンマが入らない
http://graph.facebook.com/platform/feed?date_format=U
http://developers.facebook.com/docs/reference/api/realtime/
○基本的な形式
https://graph.facebook.com/IDIDは全てのオブジェクトに対して一意に決まる数字の識別子。
人やFacebookページへのアクセスに関しては
https://graph.facebook.com/btaylor
IDに名前かページにしてもアクセス可能
○Authentication
フィードのうち公開情報として取って来れるものと取って来れないものがあって、例えば、上記のリンクにアクセスすると以下の通り。
id, name, first_name, last_name, link, username, gender, localeが拾える
{
"id": "220439",
"name": "Bret Taylor",
"first_name": "Bret",
"last_name": "Taylor",
"link": "http://www.facebook.com/btaylor",
"username": "btaylor",
"gender": "male",
"locale": "en_US"
}
これ以上の詳しい情報を取るためには
access_tokenをつけてリクエストする必要がある。
https://graph.facebook.com/btaylor?access_token=...
で取得すると以下の通り。
{
"id": "220439",
"name": "Bret Taylor",
"first_name": "Bret",
"last_name": "Taylor",
"link": "http://www.facebook.com/btaylor",
"username": "btaylor",
"hometown": {
"id": "108363292521622",
"name": "Oakland, California"
},
"location": {
"id": "109650795719651",
"name": "Los Gatos, California"
},
"work": [
{
"employer": {
"id": "20531316728",
"name": "Facebook"
},
"position": {
"id": "103112059728428",
"name": "Chief technology officer"
},
"with": [
....access_tokenの取得方法はこちらを参照
ちなみにTitaniumでこれを実現するためには
if(!Ti.Facebook.loggedIn) {
Ti.Facebook.authorize();
} else {
処理したいこと
}
でログインしていなければauthorize()メソッドでユーザーに情報許可のダイアログを表示する
○必要な情報だけを取得
queryを発行した場合、結果に余分な情報が多く含まれてくるので、必要な情報だけを取ってきたければfields=xxxのパラメーターで指定するhttps://graph.facebook.com/bgolub?fields=id,name,picture
○ロケーション情報が必要なら
/home, /feed, /postsでqueryを発行した場合にロケーション情報が必要な時はwith=locationパラメーターを追加
https://graph.facebook.com/me/home?with=location
○ 写真のサイズを変更する
Pictureへのアクセスはtype=xxxでサイズを指定できる。square (50x50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), and large (about 200 pixels wide, variable height):http://graph.facebook.com/100001696601312/picture?type=large
○クエリの結果を制限する
limitで数を、offsetは最新のものから何個目から取得するか、untilは特定日のいつまでか、sinceは特定日のいつからか。それぞれのパラメータはunixtime形式で指定する
limit,offset: https://graph.facebook.com/me/likes?limit=3until,since(a unix timestamp or any date accepted by strtotime): https://graph.facebook.com/search?until=yesterday&q=orange
○日付のフォーマットを指定する
日付のフォーマットはdate_format=xxxで指定できる。U:unixtime, r:RFC2822 format その他の形式はPHPのマニュアルを参照unixtimeは1970年1月1日00:00:00を0として表示する秒数
RFC2811は"Wed, 02 May 2012 07:47:33 +0000"という表示
残念ながらTwitterやMixiの時間表示形式は "Wed 02 May 2012 07:47:33 +0000"であり、カンマが入らない
http://graph.facebook.com/platform/feed?date_format=U
○Real-Time UpdatesというAPI
subscribe形式で関連するユーザーやページの情報が更新された場合に通知してくれるAPI。まだ中身は見れていないので、後ほどこちらを読むhttp://developers.facebook.com/docs/reference/api/realtime/
○フィードを検索する
/serachでq=xxxとtype=yyyを指定する。取得するフィードを制限したい場合はfields=zzzhttps://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE
pagingをする場合、新しいオブジェクトへのページングはその前のqueryで取得したオブジェクトの最初のcreated_timeをsinceにする。
逆に古いオブジェクトへのページングはその前のqueryで取得したオブジェクトの最後のcreated_timeをuntilに指定する
検索できるpostはのは1,2週間前まで
○投稿するとき
基本的には特定のURLにPOST要求をするhttps://graph.facebook.com/METHOD| Method | Description | Arguments |
|---|---|---|
/PROFILE_ID/feed |
Publish a new post on the given profile's feed/wall | message, picture, link, name, caption, description, source, place, tags |
/OBJECT_ID/comments |
Comment on the given object (if it has a /comments connection) |
message |
/OBJECT_ID/likes |
Like the given object (if it has a /likes connection) |
none |
/PROFILE_ID/notes |
Publish a note on the given profile | message, subject |
/PROFILE_ID/links |
Publish a link on the given profile | link, message, picture, name, caption, description |
/PROFILE_ID/events |
Create an event | name, start_time, end_time |
/EVENT_ID/attending |
RSVP "attending" to the given event | none |
/EVENT_ID/maybe |
RSVP "maybe" to the given event | none |
/EVENT_ID/declined |
RSVP "declined" to the given event | none |
/PROFILE_ID/albums |
Create an album | name, message |
/ALBUM_ID/photos |
Upload a photo to an album | message, source, place (multipart/form-data) |
/PROFILE_ID/checkins |
Create a checkin at a location represented by a Page | coordinates, place, message, tags |
TitaniumではTi.Facebook.requestWithGraphPath(URL, PARAMETER, TYPE, CALLBACK); で指定する。例えば自分のwallにpostする場合は以下。Ti.Facebook.requestWithGraphPath('me/feed', {
message : message
}, "POST", function(e) {
if(e.success) {
alert("Success" + e.result);
}
});
○投稿を削除する場合
DELETEリクエストでhttps://graph.facebook.com/ID?access_token=...
or
POSTリクエストでhttps://graph.facebook.com/COMMENT_ID?method=delete.
○参考:OBJECT_TYPE
Instance for an achievement for a user.
A photo album
An application registered on Facebook Platform
A checkin made through Facebook Places or the Graph API.
A Comment on a Graph API object
A website domain within the Graph API
A Facebook event
A Facebook friend list
A Facebook group
Statistics about applications, pages, or domain.
A shared link
A message in a thread
A Facebook Note
An Offer published by a page.
An order object associated with Facebook Credits.
A Facebook Page
An individual photo within an album
An individual entry in a profile's feed
A question asked by a user, as represented in the Graph API.
An option allowed as an answer to a question.
A review for an application
A status message on a user's wall
A subscription to an application to get real-time updates for an Graph object type.
A message thread
A user profile.
An individual video