Amazon

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

2012年4月23日月曜日

FacebookのAPIで"facebookErrDomain error 10000"

 
TitaniumでFacebookから自分のウォールの書き込みを取得しようとしていて、Ti.Facebook.requestWithGraphPath('me/home',...)
と書いてみたものの、結果は
 "facebookErrDomain error 10000"
となってしまった。むー

で、よくよく調べたら、パーミッションの問題のようでした。
Ti.Facebook.permissions = ['publish_stream'];
は自分のフィード内容を取得するのと、投稿することのみを許可するため、
友達のフィードを取得することはできない。

細かいパーミッション設定は以下を参照
http://developers.facebook.com/docs/authentication/permissions/#user_friends_perms

正解は
Ti.Facebook.permissions = ['publish_stream','read_stream'];
これだぁ。。。

2012年4月22日日曜日

2012年4月15日日曜日

Titanium MobileでiPhoneアプリを作ってAdmob広告を入れる

こちらから引用 

Adombに登録して、適当なアプリ名でアプリを登録してパブリッシャーIDは予め取得しておくこと。


Appceleratorが公開しているadmobのモジュール
https://github.com/appcelerator/titanium_modules/tree/master/admob/mobile/ios
ここにあるti.admob-iphone-xx.zip
をダウンロード。

プロジェクトディレクトリ直下(Resourcesやtiapp.xmlと同じ階層)に解凍してできたmoduleフォルダをコピー。tiapp.xml内の下の方にある、
<modules></modules>

の部分を

<modules>
        <module version="1.0">ti.admob</module>
</modules>
に、
app.jsに
Titanium.Admob = require('ti.admob');

var adview = Titanium.Admob.createView({
    top:0,
    testing:true,
    adBackgroundColor:'black',
    primaryTextColor:'blue',
    secondaryTextColor:'green',
    publisherId:'<< your ID>>' // Replace this string with your own API key!
});
win.add(adview);
を追加。
publisherIdにadMobの管理画面のアプリケーションの設定管理のページに表示されているパブリッシャーIDを入れれば完了。
これだけ。


[その他参考]
http://d.hatena.ne.jp/d_sea/20120124/1327375488

Amazon3