-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook_inc.php
66 lines (56 loc) · 1.86 KB
/
facebook_inc.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
<?php
# Facebook code
# See http://xenonxm.blogspot.com/2009/06/
# photo-upload-to-facebook-from-your-php.html
# for reference. Also,
# http://www.easycodingclub.com/facebook-api-tutorials/
# facebook-php-api-for-photos-upload
function doFacebook() {
session_start();
$facebook = new FacebookPhotos($GLOBALS['FB_API_KEY'],
$GLOBALS['FB_SECRET']);
if ($_REQUEST['fb'] == 'auth') {
$album = $_SESSION['album'];
if (!file_exists("a_$album")) {
print "Please navigate here from the main album page";
exit(0);
}
$desc = getAlbumDescription($album);
$fb_sig_user = $_REQUEST['fb_sig_user'];
# First create the album
$create_album_response = $facebook->api_client->photos_createAlbum(
$desc, '', '', '', $fb_sig_user);
$album_link = $create_album_response['link'];
$aid = $create_album_response['aid'];
print "Created album <a href='$album_link'>$desc</a><br/>\n";
flush();
$photos = getPhotoList($album);
$num_photos = count($photos);
print "Found $num_photos photos<br/>\n";
flush();
foreach ($photos as $photo) {
try {
$file = "a_$album/m/m_$photo";
$photo_desc = getPhotoDescription($album, $photo);
if (file_exists($file)) {
$upload_response = $facebook->api_client->photos_upload(
$file, $aid, $photo_desc, $fb_sig_user);
$photo_link = $upload_response['link'];
print "Uploaded photo <a href='$photo_link'>$photo</a><br/>\n";
flush();
} else {
print "Skipping nonexistant file $file<br/>\n";
flush();
}
} catch (Exception $e) {
print "Caught exception uploading $photo<br/>\n";
flush();
}
}
print "Done<br/>";
} else {
$_SESSION['album'] = $_REQUEST['fb'];
$facebook->require_frame();
}
}
?>