/
index2.php
73 lines (58 loc) · 1.77 KB
/
index2.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
echo 'hello friend!';
ini_set('memory_limit', '-1');
error_reporting(0);
echo "starting...\n";
$url = 'CHANGE THIS TO YOUR API LINK';
myFunction($url);
echo '<br/>done';
function CallAPI($method, $url, $data = false, $header=null)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 0);
//echo $curl;
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
function getToken(){
$token = CallAPI('POST','');
return array("Authorization: $token");
}
function myFunction($link){
$header = getToken();
$res = CallAPI('GET',$link, false, $header);
$var = json_decode($res);
$path = dirname(__FILE__). "/files/";
$file = $path."Page_".$var->paging->currentPage.".json";
echo $file;
echo $var->paging->currentPage;
file_put_contents($file, json_encode($var->list));
//@todo put logs here $var->paging->next
file_put_contents('script.log', "link: ". $var->paging->next . " Page: ".$var->paging->currentPage . "\n" , FILE_APPEND);
if($var->paging->currentPage != $var->paging->totalPage){
echo $var->paging->next;
myFunction($var->paging->next);
}
}
?>