forked from hashirshykh/facebookpostsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
36 lines (25 loc) · 879 Bytes
/
post.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
<?php
require('./src/Facebook/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => '{YOUR APP ID }',
'app_secret' => '{YOUR APP SECRET}',
'default_graph_version' => 'v2.10',
]);
$data = [
'message' => 'My awesome photo upload example.',
'link' => 'http://www.example.com',
'source' => $fb->fileToUpload('./src/Facebook-logo.png'),
];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/photos', $data, '{YOUR PAGE ACCESS TOKEN }');
} 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;
}
$graphNode = $response->getGraphNode();
echo 'Posted with id: ' . $graphNode['id'];
?>