Skip to content

Instantly share code, notes, and snippets.

@okremer84
Created March 22, 2020 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okremer84/b43db412a708d2024b77e284b2c89b94 to your computer and use it in GitHub Desktop.
Save okremer84/b43db412a708d2024b77e284b2c89b94 to your computer and use it in GitHub Desktop.
Get all livechat chats
<?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