-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
77 lines (65 loc) · 2.4 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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
session_start();
require('facebook-php-sdk-v4-4.0-dev/autoload.php');
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
const APPID = "743593195754749";
const APPSECRET = "d3bbc76ac84862edf3d726353a10b77c";
FacebookSession::setDefaultApplication(APPID, APPSECRET);
$helper = new FacebookRedirectLoginHelper('https://facebookphotoesgi.herokuapp.com/');
if(isset($_SESSION) && isset($_SESSION['fb_token'])){
$session = new FacebookSession($_SESSION['fb_token']);
} else {
$session = $helper->getSessionFromRedirect();
}
$loginUrl = $helper->getLoginUrl();
if($session){
try{
$user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
echo "Nom : ". $user_profile->getName();
}
catch(FacebookRequestException $e){
echo "Exception occured code : ". $e->getCode();
echo " with message ". $e->getMessage();
}
} else {
echo "Veuillez vous <a href='".$loginUrl."'> connecter</a>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome to Facebook App</title>
<meta name="description" content="Description de ma page" >
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo APPID; ?>',
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>
</head>
<body>
<div
class="fb-like"
data-share="true"
data-width="450"
data-show-faces="true">
</div>
</body>
</html>