Amazon

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

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年9月17日月曜日

facebookErrDomain error 10000.

Titaniumを使ってFacebookのpostアプリを作る時にハマった事。

以下のようなメソッドとパラメーターを入れてPostするが、

Ti.Facebook.requestWithGraphPath(url, parameters, "POST"function(e) {...}


The operation couldn't be completed. (facebookErrDomain error 10000.)

という結果が返って来た。

urlをよく確認すると'me/home'になっていた。'me/home'はフィードを読み込むためのものであり、GETするもの。
'me/feed'は自分が投稿したものを得るのであり、POSTするもの。

この小さな違いに少しハマりました。

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

2011年2月20日日曜日

Facebookページ(旧:ファンページ)のFBML新規追加不可



FacebookのFacebookページ(旧:ファンページ)が3/11より新規のStatic FBMLを追加できなくなる仕様に変更されて、iframeで取り込むことを推奨するようです。やはりFacebook上にコンテンツを持ち続けるのはデータ量が半端なくなってるせいかな。

ということで以下抜粋。

こちらより


3月11日以降、Static FBMLの新規追加できなくなる。

2月 13th, 2011 by admin
Facebookページを自由に編集することができるアプリ 「Static FBML」の新規追加が3月11日以降、できなくなることになりました。 「Facebook開発者ブログ」は昨日、「Facebookページ(旧ファンページ)で使用されていた、FBMLは3月10日までに非推奨規格とされ、staticFBMLを使用したページ新設はできなくなる。」と発表しました。 ちなみに現在のFBMLが3月11日以降、動かなくなることは無いようです。(新規追加ができなくなるということです) 今後はiframe(インラインフレーム)で、タブをつくり、中の記述は、HTML、JAVASCRIPT、CSS、Flash つまり一般的なWEB言語で構築できるよう仕様変更されます。 今までは使えなかった「iframe(インラインフレーム)」というタグが推奨されています。 「iframe(インラインフレーム)」とは簡単に言えば ページの中に別のページを表示できる仕組みの事で 表示させたい場所にのタグを入れます。 幅・高さ・表示させたいページ・name等の属性を指定してあげると 自由なデザインで簡単に使用できます。 これまでのFBMLで作ったコンテンツは、Facebook上のサーバーの中にある状態でした。 「iframe(インラインフレーム)」だとFacebook上ではなく 個々のユーザーのサーバーの中にコンテンツを入れ それをページのタブを通して表示させる、という方法になります。 自分が管理しているWebページのコンテンツなので自由に表現ができるようになります。 つまり今回の変更でFacebookページ管理者にとっては Facebookページの自由度がより高くなったことになります。



そんなわけでFacebookページにiframeを取り込む方法は以下を参照

FacebookページにiFrameを組み込もう

Amazon3