-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.php
97 lines (79 loc) · 3.79 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
define('EYEEM_CLIENT_ID', '');
define('EYEEM_CLIENT_SECRET', '');
require_once __DIR__ . '/autoload.php';
session_start();
$eyeem = new Eyeem();
$eyeem->setClientId(EYEEM_CLIENT_ID);
$eyeem->setClientSecret(EYEEM_CLIENT_SECRET);
// Sign Out
if (isset($_GET['signout'])) {
unset($_SESSION['token']);
header('Location:' . Eyeem_Utils::getCurrentUrl(array('signout')));
exit;
// oAuth callback
} else if (isset($_GET['code'])) {
$_SESSION['token'] = $token = $eyeem->getToken($_GET['code']);
$eyeem->setAccessToken($token['access_token']);
header('Location:' . Eyeem_Utils::getCurrentUrl(array('code', 'state')));
exit;
// Authenticated
} else if (!empty($_SESSION['token']['access_token'])) {
$eyeem->setAccessToken($_SESSION['token']['access_token']);
}
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>EyeEm Client - Example</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css"/>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="content">
<div class="page-header">
<h1>EyeEm Client - Example</a></h1>
</div>
<?php if ($accessToken = $eyeem->getAccessToken()) : ?>
<p>Authenticated. <a href="?signout=1">Sign Out</a></p>
<p>Access Token: <b><?php echo $accessToken ?></b></p>
<hr/>
<ul class="nav nav-pills">
<li class="me"><a href="?part=me">Me</a></li>
<li class="photos"><a href="?part=photos">Photos</a></li>
<li class="friends"><a href="?part=friends">Friends</a></li>
<li class="friendsPhotos"><a href="?part=friendsPhotos">Friends Photos</a></li>
</ul>
<?php if (empty($_GET['part']) || $_GET['part'] == 'me') : ?>
<h3>Me</h3>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getRawArray(), JSON_PRETTY_PRINT); ?></pre></p>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getRawArray(), JSON_PRETTY_PRINT) ?></pre></p>
<script>jQuery(function($) { $('.me').addClass('active'); })</script>
<?php elseif ($_GET['part'] == 'photos') : ?>
<h3>My Photos</h3>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getPhotos()->getItems(), JSON_PRETTY_PRINT); ?></pre></p>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getPhotos()->getItems(), JSON_PRETTY_PRINT) ?></pre></p>
<script>jQuery(function($) { $('.photos').addClass('active'); })</script>
<?php elseif ($_GET['part'] == 'friends') : ?>
<h3>My Photos</h3>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getFriends()->getItems(), JSON_PRETTY_PRINT); ?></pre></p>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getFriends()->getItems(), JSON_PRETTY_PRINT) ?></pre></p>
<script>jQuery(function($) { $('.friends').addClass('active'); })</script>
<?php elseif ($_GET['part'] == 'friendsPhotos') : ?>
<h3>Friends Photos</h3>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getFriendsPhotos(array('limit' => 3))->getItems(), JSON_PRETTY_PRINT); ?></pre></p>
<p><pre><?php echo json_encode($eyeem->getAuthUser()->getFriendsPhotos(array('limit' => 3))->getItems(), JSON_PRETTY_PRINT) ?></pre></p>
<script>jQuery(function($) { $('.friendsPhotos').addClass('active'); })</script>
<?php else: ?>
<p>Unknown part.</p>
<?php endif ?>
<?php else : ?>
<p>Not Authenticated. <a href="<?php echo $eyeem->getLoginUrl(); ?>">Sign In</a></p>
<?php endif ?>
<hr/>
</div>
</div>
</body>
</html>