-
Notifications
You must be signed in to change notification settings - Fork 1
/
dailycredClass.php
73 lines (35 loc) · 1.25 KB
/
dailycredClass.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
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class dailycred {
private $oauth_url = 'https://www.dailycred.com/oauth/';
private $graph_url = 'https://www.dailycred.com/graph/me.json?';
private $client_id = 'Add client id here';
private $client_secret = 'Add client secret here';
public function generate_url($param){
$signin_url = $this->oauth_url.'authorize?action='.$param.'&client_id='.$this->client_id;
return $signin_url;
}
private function exchange_code($code){
$exchange_url = $this->oauth_url.'access_token?code='.$code.'&client_secret='.$this->client_secret;
$atoken_json = $this->get_with_curl($exchange_url);
if($atoken_json->worked === true){
$access_token = $atoken_json->access_token;
return $access_token;
}
}
public function graph_request($code){
$get_a_token = $this->exchange_code($code);
$graph_request_url = $this->graph_url.'access_token='.$get_a_token;
$get_response = $this->get_with_curl($graph_request_url);
return $get_response;
}
private function get_with_curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
$obj = json_decode($data);
return $obj;
}
}
?>