-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
36 lines (29 loc) · 1.08 KB
/
lib.php
File metadata and controls
36 lines (29 loc) · 1.08 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
<?php
function request($requestUrl, $accessToken, $action, $fields = [], $post = true) {
$requestUrl = $requestUrl . '/' . $action . '.json?access_token=' . $accessToken;
$fields = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$requestHeaders = array(
'Content-Type: application/x-www-form-urlencoded; ',
'Content-Length: ' . strlen($fields),
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
}
$response = curl_exec($ch);
$result = json_decode($response, true);
if ($result === null) {
echo "\nGot NULL Response. Actual response: \n";
var_dump($response);
echo curl_error($ch);
}
curl_close($ch);
return $result;
}