-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
89 lines (77 loc) · 2.06 KB
/
index.php
File metadata and controls
89 lines (77 loc) · 2.06 KB
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
<?php
session_start();
require_once __DIR__ . '/vendor/autoload.php' ;
require 'config.php';
$fb = new Facebook\Facebook([
'app_id' => $appid,
'app_secret' => $appsecret,
'default_graph_version' => 'v2.5',
]);
?>
<!DOCTYPE html>
<html>
<head>
<title> Application FB</title>
<script type="text/javascript" src="public/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="public/js/script.js"></script>
</head>
<body>
<h1>Page du projet</h1>
<?php if(isset($_SESSION["ACCESS_TOKEN"])) :?>
<a href="logout.php">Se déconnecter </a><br /> <br />
<?php
$fb->setDefaultAccessToken($_SESSION["ACCESS_TOKEN"]);
try
{
$response = $fb->get('/me');
$userNode = $response->getGraphUser();
}
catch(Facebook\Exceptions\FacebookResponseException $e)
{
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e)
{
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo 'Logged in as ' . $userNode->getName();
?>
<br /> <br />
<?php
try
{
$response = $fb->get('/me/albums');
$albums = $response->getDecodedBody();
//var_dump($albums);
foreach($albums["data"] as $album)
{
echo "<h1>".$album['name']."</h1>";
$response = $fb->get('/'.$album["id"]."/photos?fields=id,source");
$photos = $response->getDecodedBody();
foreach($photos["data"] as $photo)
{
echo "<img style='width:150px' src='".$photo["source"]."' /> <br />";
}
}
}
catch(Facebook\Exceptions\FacebookResponseException $e)
{
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e)
{
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
?>
<?php else:?>
<?php endif; ?>
</body>
</html>