Created
March 22, 2020 21:33
-
-
Save okremer84/b43db412a708d2024b77e284b2c89b94 to your computer and use it in GitHub Desktop.
Get all livechat chats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('config.php'); | |
$handle = curl_init(); | |
$file = __DIR__ . DIRECTORY_SEPARATOR . "backup.log"; | |
$file = fopen($file, "w"); | |
$url = "https://api.livechatinc.com/v2/chats/"; | |
curl_setopt_array($handle, | |
array( | |
CURLOPT_URL => $url, | |
CURLOPT_HTTPAUTH => CURLAUTH_ANY, | |
CURLOPT_USERPWD => USERNAME . ":" . PASSWORD, | |
CURLOPT_RETURNTRANSFER => true, | |
) | |
); | |
$data = curl_exec($handle); | |
$decoded = json_decode($data); | |
$num_pages = $decoded->pages; | |
$num_pages = 3; | |
$split_file_at = round($num_pages / 2); | |
for ($i = 1; $i <= $num_pages; $i++) { | |
$url = "https://api.livechatinc.com/v2/chats/?page=$i"; | |
curl_setopt_array($handle, | |
array( | |
CURLOPT_URL => $url, | |
CURLOPT_HTTPAUTH => CURLAUTH_ANY, | |
CURLOPT_USERPWD => USERNAME . ":" . PASSWORD, | |
CURLOPT_RETURNTRANSFER => true, | |
) | |
); | |
if ($split_file_at == $i) { | |
fclose($file); | |
$file = __DIR__ . DIRECTORY_SEPARATOR . "backup_2.log"; | |
$file = fopen($file, "w"); | |
} | |
$data = curl_exec($handle); | |
$info = curl_getinfo($handle); | |
fwrite($file, $data); | |
} | |
fclose($file); | |
curl_close($handle); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment