-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish-post.php
52 lines (44 loc) · 1.37 KB
/
publish-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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Author : Habib urRehman
* Email : chaudryhabib2@gmail.com
* Github : https://github.com/oldravian
* Website: http://redravian.com/
*/
//turn on php error handling
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
function pagePost($data){
$message = $data['message'];
$link = $data['link'];
$env = parse_ini_file('.env');
$client = new Client();
try{
$qry = [
'message' => $message,
'link' => $link,
'access_token' => $env['long_lived_page_access_token']
];
//get a long-lived User access token
$response = $client->request('POST', "https://graph.facebook.com/" . $env['facebook_page_id'] . "/feed", [
'query' => $qry
]);
$body = $response->getBody();
$data = json_decode($body->getContents());
echo "Posted Successfully!";
}
catch (\GuzzleHttp\Exception\RequestException $e){
if ($e->hasResponse()) {
$response = $e->getResponse();
var_dump($response->getReasonPhrase()); // Response message;
var_dump(json_decode((string) $response->getBody())); // Body as the decoded JSON;
}
else{
var_dump($e->getMessage());
}
}
}
?>