-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
108 lines (87 loc) · 2.86 KB
/
index.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
98
99
100
101
102
103
104
105
106
107
108
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
session_start();
require('facebook_api_4.4.0/autoload.php');
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookSDKException;
use Facebook\GraphUser;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;
require('constant.php');
FacebookSession::setDefaultApplication(APPID, APPSECRET);
$helper = new FacebookRedirectLoginHelper(REDIRECT_URL);
if(isset($_SESSION) && isset($_SESSION['fb_token'])){
$session = new FacebookSession($_SESSION['fb_token']);
}else{
$session = $helper->getSessionFromRedirect();
}
if($session){
try{
$token = (string) $session->getAccessToken();
$_SESSION['fb_token'] = $token;
$user_profile = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject("Facebook\GraphUser");
$prenom = $user_profile->getFirstName();
$nom = $user_profile->getLastName();
$id = $user_profile->getId();
//echo "Name: ".$user_profile->getName();
}catch(FacebookRequestException $e){
echo 'erreur';
}
}else{
$loginUrl = $helper->getLoginUrl(['user_photos']);
$message = 'Not connected. Please <a href="'.$loginUrl.'">Connect</a>';
//echo 'Not connected. Please <a href="'.$loginUrl.'">Connect</a>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Facebook App</title>
<meta name="description" content="App Facebook">
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="./css/magnific-popup.css">
</head>
<body>
<script src="./js/jquery-1.11.2.min.js"></script>
<div class="container">
<div class="jumbotron">
<h1>Concours photos iVents</h1>
<p>
Mettez en ligne votre meilleure photo de soirée.
<?php if(!$session) {
echo $message;
}?>
</p>
</div>
<?php
if($session){
require('gridPhotos.php');
}
?>
</div><!-- /.container -->
<script src="./js/bootstrap.min.js"></script>
<script src="./js/magnific-popup.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '921813551202473',
xfbml : true,
version : 'v2.3'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/fr_FR/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</body>
</html>