Friday, February 17, 2012

Facebook 檢查是否有點擊讚按鈕 (Likes)

$appId = '1234567890'; // Facebook App Id
$res = $this->facebook->api('/me/likes/' . $appId);
回傳值:
{
  "data": [
    {
      "name": "應用程式名稱",
      "category": "Application",
      "id": "1234567890",
      "created_time": "2012-02-17T07:54:54+0000"
    }
  ],
  "paging": {
    "next": ""
  }
}
use FQL:
$appId = 1234567890;

$query = array(
  'likes' => "SELECT uid, page_id, type, profile_section, 
                     created_time FROM page_fan
              WHERE uid = me() AND 
                    page_id = "' . $appId . '",
);

/**
 * 回傳值
 * $response = array(
 *   array(
 *     'name' => 'likes',
 *     'fql_result_set' => array(
 *       array(
 *         "created_time" => "1329468255",
 *         "page_id" => "1234567890",
 *         "profile_section" => "other",
 *         "type" => "APP",
 *         "uid" => "100000119629520"
 *       )
 *     )
 *   )
 * );
 */
$responses = $this->facebook->api(
  array(
    'method' => 'fql.multiquery',
    'queries' => $query
  )
);
Facebook Javascript Like button click event:
FB.Event.subscribe('edge.create',
  function(response) {
    //alert('You liked the URL: ' + response);
  }
);