Last active
December 23, 2015 19:09
-
-
Save c-taka/6681023 to your computer and use it in GitHub Desktop.
FacebookでログインするWebサービスを作ろう
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 | |
| require_once('config.php'); | |
| session_start(); | |
| function h($s) { | |
| return htmlspecialchars($s, ENT_QUOTES, "UTF-8"); | |
| } | |
| // ログインチェック | |
| if (empty($_SESSION['user'])) { | |
| header('Location: '.SITE_URL.'login.php'); | |
| exit; | |
| } | |
| // 友達情報の取得 | |
| $url = "https://graph.facebook.com/me/friends?access_token=".$_SESSION['user']['facebook_access_token']; | |
| $friends = json_decode(file_get_contents($url)); | |
| //var_dump($friends); | |
| //exit; | |
| ?> | |
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Facebook Friends</title> | |
| </head> | |
| <body> | |
| <h1>Facebook Friends</h1> | |
| <div> | |
| <img src="<?php echo h($_SESSION['user']['facebook_picture']); ?>"> | |
| </div> | |
| <p><?php echo h($_SESSION['user']['facebook_name']); ?>としてログインしています。</p> | |
| <ul> | |
| <?php foreach ($friends->data as $friend) : ?> | |
| <li><?php echo h($friend->name); ?></li> | |
| <?php endforeach; ?> | |
| </ul> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment