forked from otarhe/training-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpressable_api_connection_web.php
More file actions
75 lines (55 loc) · 1.73 KB
/
pressable_api_connection_web.php
File metadata and controls
75 lines (55 loc) · 1.73 KB
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
67
68
69
70
71
72
73
74
75
<?php
/*
Plugin Name: Pressable API connection web application
Description: Demonstrating how to access the Pressable API using a simple web application
Plugin URI: https://pressable.com/
Author: Obatarhe Otughwor
Version: 1.0
*/
$curl = curl_init();
$auth_data = array(
'client_id' => 'ADD-CLIENT-ID-HERE',
'client_secret' => 'ADD-CLIENT-SECRET-HERE',
'grant_type' => 'client_credentials'
);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $auth_data);
curl_setopt($curl, CURLOPT_URL, 'https://my.pressable.com/auth/token');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$results = curl_exec($curl);
if(!$results){die("Connection Failure");}
curl_close($curl);
$results = json_decode($results, true);
echo "Bearer token:" . '<br/>';
$res = print_r($results["access_token"]);
echo $res;
echo " </br>";
echo " </br>";
echo " </br>";
$token = $results["access_token"];
$b = 'Authorization: Bearer ';
$curl = curl_init();
curl_setopt_array($curl, array(
//Pressable API request URL example: https://my.pressable.com/v1/sites
CURLOPT_URL => "https://my.pressable.com/v1/sites/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//You can chnage the request method from GET to POST or any method
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
$b . $token,
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
echo "Responses:" . '<br/>';
//Decode result
$results = json_decode($response, true);
echo '<pre>';
print_r($results);