facebookのタイムラインを根こそぎ持ってくる

facebookの特定ページのタイムラインを根こそぎ持ってくる方法です。

まずは、タイムライン情報の取得に必要なApp IDとApp Secretをディベロッパーページより作成し、取得します。

<?php

//
$app_id = ""; //App ID
$secret_id = ""; //App Secret

//
$want_face_book_page_id = ""; //取得したいfacebookページの https://www.facebook.com/xxxxx のxxxxの部分

//
$access_token = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id={$app_id}&client_secret={$secret_id}&grant_type=client_credentials");
$url = "https://graph.facebook.com/{$want_face_book_page_id}/posts?".$access_token;

$res = file_get_contents($url);
file_put_contents("facebook_timeline_{$want_face_book_page_id}_0.json",$res);

$cnt = 1;
$res = json_decode($res, TRUE );

while( $res["paging"]["next"] ){

  $res = file_get_contents($res["paging"]["next"]);
  file_put_contents("facebook_timeline_{$want_face_book_page_id}_{$cnt}.json",$res);

  $res = json_decode($res, TRUE );

  $cnt ++;

}