【问题标题】:Not getting all chats in livechat api没有在 livechat api 中获得所有聊天
【发布时间】:2015-12-31 08:48:28
【问题描述】:

此代码仅返回当天的聊天记录。并非所有从 2015 年 1 月 1 日开始。我现在应该怎么做才能获取给定日期的所有聊天记录。

$url = "https://api.livechatinc.com/chats?\date_from=2015-01-01";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

$result = curl_exec($curl);
echo $result;

【问题讨论】:

  • 我不知道这个 api 是如何工作的(没有看到它的文档和任何东西)但是这个反斜杠 chats?\date_from 对我来说看起来很可疑

标签: php curl livechat


【解决方案1】:

请看一下这段代码:

<?php

$url = "https://api.livechatinc.com/chats?date_from=2015-01-01";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-API-Version: 2'));    

$result = curl_exec($curl);
$result = json_decode($result);

print_r($result);

这是对我们 API 的正确请求,它从 2015-01-01 开始检索聊天记录。聊天从最新到最旧排序,这意味着最旧的聊天将在最后一页找到。

请确保您使用 API v2,我们强烈推荐:https://developers.livechatinc.com/rest-api/

我们将在 2 周后引入 sort_order 参数。 我们还在 github 上提供并推荐我们自己的库。它提供了所有可能的 api 请求。

干杯, 亚当

【讨论】:

  • 它只检索当前日期聊天。并非所有 2015 年 1 月 1 日的聊天记录
  • 尝试将page 参数添加到最后一页,例如link,其中20 是最后一页。每当您请求聊天 api 时,它都会返回聊天数和页数 link。您可以在我们的文档link 中找到更多信息。干杯亚当
  • @LiveChatAdam 这将通过分页检索数据,有没有办法在单个页面上列出所有聊天?
猜你喜欢
  • 2017-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-06
  • 2017-08-22
  • 2021-06-05
  • 1970-01-01
相关资源
最近更新 更多