-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook_test.php
65 lines (50 loc) · 1.76 KB
/
facebook_test.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
<style type="text/css">
img {
filter:grayscale(100%);
opacity:0.5;
height:200px;
}
img:hover {
filter:none;
opacity:0.9;
}
</style>
<?php
require_once 'vendor/autoload.php';
if(!session_id()) {
session_start();
}
// make sure you have enough time to download all pictures
ini_set('max_execution_time', 6000);
ini_set('memory_limit', '64M');
$app_id = '673050199540698';
$app_secret = 'febd8e346ea6fda591f5709b6d00039d';
$page_id = '647380205348927';
$fb = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => 'v2.8',
]);
// TO OBTAIN ACCESS TOKEN
/*$helper = $fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl('http://localhost/creaphy/facebook_callback.php', $permissions);
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
var_dump($_SESSION);
$helper = $fb->getPageTabHelper();
$accessToken = $_SESSION['fb_access_token'];
if (!isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}*/
// long lived acces token
$accessToken = "EAAJkIrYPQ9oBABwZBwzxWhuZCLuPmWFTZBgnjAKWfS3sISBWIm60hSqklLY5Hvjk0lXQDwv7MTXPTbs3tGZAkTUl5qfW9ZBnojnrhJmb1zWLSR6HKlL8lGO8Xeixos779ixWjZCXnvTgFTl96ZBiPdI7VNBU1UZAuAmHl0FYjqWuzAZDZD";
// get all photos (no specific album) with limit set to 50 (enough)
$page = $fb->get('/'.$page_id."/photos/uploaded?limit=50", $accessToken);
$photos = $page->getDecodedBody();
foreach ($photos['data'] as $photo) {
$photo_id = $photo['id'];
// print the image with link to facebook
echo '<a target="_blank" href="https://www.facebook.com/photo.php?fbid='.$photo_id.'&theater"><img src="https://graph.facebook.com/'.$photo_id.'/picture"/></a>';
}
?>