Amazon

ラベル Graph API の投稿を表示しています。 すべての投稿を表示
ラベル Graph API の投稿を表示しています。 すべての投稿を表示

2012年9月30日日曜日

Facebook Graph APIで写真が属しているアルバムIDを取得する

FacebookのiPhoneアプリのように、画像を表示して画面をスイープしたら次の画像を取得する方法を探している。


アルバムのIDリストを取得するには以下の通り
https://graph.facebook.com/*my_id*/albums?access_token=*access_token*
さらにアルバムのIDが決まればそこに含まれる写真のIDリストは以下で取れるようです。
https://graph.facebook.com/*album_id*/photos?access_token=*access_token*
が、ある写真がどのアルバムに属するかはわからないので、それを調べたい。


そこで考えた方法は
表示した画像のIDを取得して、その画像が属するAlbum IDを取得。
ただ、Graph APIでは取れなさそうで、FQLを使う様子




ドキュメントはこちら
http://developers.facebook.com/docs/reference/fql/photo/

参考FQLはこちら
select aid, album_object_id from photo where object_id = ${GRAPH_PHOTO_ID}

うーん、めんどくさい。。。

2012年7月29日日曜日

Facebook Graph APIでaccess_tokenを延期する方法

通常のFacebookの認証だと1,2時間で認証が切れてしまうので、それを延ばすための方法。

こちらより自分のapp_id, app_secretを取得
https://developers.facebook.com/apps

さらにアプリのSetting -> AdvancedでRemove offline_access permissionをenableにする必要がある

access_tokenを更新するためのリクエスト方法は以下。公式ドキュメントはこちら

https://graph.facebook.com/oauth/access_token?             
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN 

TitaniumでEXISTING_ACCESS_TOKENは
http://docs.appcelerator.com/titanium/2.1/index.html#!/api/Titanium.Facebook

Ti.Facebook.accessTokenでアクセスできるみたい。
authorize()後にアクセスすると取得可能になるみたい。
ちなみにTi.Facebook.appidもいける。

もしくはgetAccessToken()かgetAppid()でも良い。
あとは()でリクエストすることになるのかな。

2012年6月9日土曜日

Graph APIで写真にタグ付けする


FacebookのGraph APIで写真にタグ付けをする場合のパラメータは以下

Photo #tag


ParameterDescriptionTypeRequired
toUSER_ID of the User to tag; can also be provided in URL path (see above).stringOne of to ortag_text
tag_textA text string to tag.stringOne of to ortag_text
xx coordinate of tag, as a percentage offset from the left edge of the picturenumberno
yy coordinate of tag, as a percentage offset from the top edge of the picturenumberno

If the write is successful, you get the following return.
DescriptionType
If the update succeededboolean

2012年6月3日日曜日

Facebook GraphAPIで友達と一緒にいることを伝えるAPI

*****今のところ、Facebookのbugらしく、Graph APIからのwith_tagsは投稿できない様子。with_tagsやtoを投稿しても消えてしまうみたい。
http://developers.facebook.com/bugs/334390446603278***


FacebookのGraphAPIを使って、"○○さんと一緒にいます"というような投稿をする場合、実際にFacebookにpostする際には"with_tags"というパラメーターをつける。

Graph APIのドキュメントによれば

with_tagsObjects (Users, Pages, etc) tagged as being with the publisher of the post ("Who are you with?" on Facebook)read_streamobjects containing id and name fields, encapsulated in a data[] array
とのことなので
Titaniumでのリクエストの書き方としては、paramatersという連想配列を定義して、
 Ti.Facebook.requestWithGraphPathの第二引数に指定するのが、汎用的な方法


function postFB(parameters) {
    if(!Ti.Facebook.loggedIn) {
        Ti.Facebook.authorize();
    }
    var paramater {
        message : "with Friend, xxx",
        with_tags : {
            data : [{
                id : id,
                name : name
            }]
        }
    };


    Ti.Facebook.requestWithGraphPath('me/feed', parameters, "POST", function(e) {
        if(e.success) {
            alert("Success" + e.result);
        }
    });
}



2012年4月30日月曜日

Facebook Graph APIのメモ

使い方はここを読んでもらうとして、必要なところだけまとめると

○基本的な形式

https://graph.facebook.com/ID
IDは全てのオブジェクトに対して一意に決まる数字の識別子。
人や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形式で指定する

○日付のフォーマットを指定する

日付のフォーマットは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=zzz
https://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

Amazon3