Skip to content

Instantly share code, notes, and snippets.

@c-taka
Last active December 23, 2015 19:09
Show Gist options
  • Select an option

  • Save c-taka/6681023 to your computer and use it in GitHub Desktop.

Select an option

Save c-taka/6681023 to your computer and use it in GitHub Desktop.
FacebookでログインするWebサービスを作ろう
<?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