-
Notifications
You must be signed in to change notification settings - Fork 0
/
share_photo.php
executable file
·56 lines (47 loc) · 1.33 KB
/
share_photo.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
<?php
session_start();
require_once __DIR__ . '/src/Facebook/autoload.php';
require_once 'campaign/campaign.php';
//try {
$access_token = "";
if (isset($_POST['access_token'])) {
$access_token = $_POST['access_token'];
$_SESSION['fb_access_token'] = (string) $access_token;
} else {
die ("No access token provided");
}
$source = '';
if (isset($_POST['source'])) {
$source = $_POST['source'];
} else {
die ('No image provided');
}
$message = '';
if (isset($_POST['message'])) {
$message = $_POST['message'];
}
$fb = new Facebook\Facebook([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => 'v2.6',
]);
//getting campaign url to message
$campaign = new Campaign();
$detail = $campaign->get_campaign_by_id($_SESSION['campaign_id']);
$url = $campaign->get_campaign_url($_SESSION['campaign_id']);
$data = [
'message' => $detail['title'].'. Created with '.$url,
'source' => $fb->fileToUpload($source),
];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/photos', $data, $access_token);
echo "ok";
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
?>