Created
March 19, 2012 01:26
-
-
Save mgng/2089189 to your computer and use it in GitHub Desktop.
facebook API を使ってニュースフィードを取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$app_id = 'あなたのapp ID'; | |
$app_secret = 'あなたのapp secret key'; | |
$my_url = 'あなたのapp url'; | |
$code = isset($_GET['code']) ? $_GET['code'] : ''; | |
if ( $code === '' ) { | |
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id={$app_id}&scope=read_stream&redirect_uri=".urlencode($my_url); | |
echo "<a href=\"{$dialog_url}\">認証+アプリ連携開始</a>"; | |
} else { | |
$token_url = "https://graph.facebook.com/oauth/access_token?client_id={$app_id}&client_secret={$app_secret}&code={$code}&redirect_uri=".urlencode($my_url); | |
$access_token = file_get_contents( $token_url ); | |
if ( $access_token === false ) { | |
echo '認証失敗'; | |
} else { | |
$graph_url = "https://graph.facebook.com/me/home?{$access_token}"; | |
$data = json_decode( file_get_contents( $graph_url ) ); | |
// $data にニュースフィードデータが入ってくる | |
echo '<pre>' . print_r( $data, true ) . '</pre>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment