-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassy.php
61 lines (50 loc) · 1.35 KB
/
classy.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
<?php
/*
* @Package: Classy
* @Author: Eric Stout (factor1)
* @Version: 0.0.1
*
*/
// Assumes Guzzle added through Composer,
// @link http://getcomposer.org
// @link http://guzzlephp.org
require_once('vendor/autoload.php');
require_once('secret.php');
// Substitute w/ your own values. PROTECT YOUR SECRET. Do not put in public repo!
$clientId = 'UlLPejurQ4ulTl27';
$clientSecret = $secret;
$client = new GuzzleHttp\Client();
try {
// Use credentials to receive access token
$response = $client->request(
'POST',
'https://api.classy.org/oauth2/auth',
[
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => $clientId,
'client_secret' => $clientSecret
]
]
);
$result = json_decode($response->getBody(), true);
$accessToken = $result['access_token'];
} catch (Exception $ex) {
// Handle ...
echo $ex->getMessage() . "\n";
}
// Now use that token to make all subsequent requests
// Fetch a campaign
function getclassy($accessToken, $client){
$response = $client->request(
'GET',
'https://api.classy.org/2.0/campaigns/91466',
[
'headers' => [
'Authorization' => "Bearer $accessToken"
]
]
);
echo $response->getBody();
}
getclassy($accessToken, $client);