【问题标题】:cURL get the API data to show in php table [closed]cURL 获取 API 数据以显示在 php 表中 [关闭]
【发布时间】:2020-08-08 12:31:51
【问题描述】:

我有这个 api 有很多广告系列,我需要显示上个月的特定广告系列,比如广告系列的名称和状态,但我不知道该怎么做..

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Campaign Exclude App</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<h1>Campaigns</h1><br>
<input type="text" name="" id="">
<input type="submit">
<table class="table">
  <thead class="thead-dark">
    <tr>
      <th scope="col">Id</th>
      <th scope="col">Campaign Name</th>
      <th scope="col">CPA Goal</th>
      <th scope="col">Click Amount</th>
    </tr>
  </thead>
</table>

<?php
$url='https://www.popads.net/api/campaign_list?key=9a790b65025e0aa449e60384a87b56e97c3ebf39';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$resultArray = json_decode($result);
echo "<pre>";
print_r($resultArray);
?>
</body>
</html>

Image added

【问题讨论】:

  • campaign_list 将列出所有广告系列。您可以使用 PHP 函数过滤结果。如果您有任何其他参考资料。您可以在问题内分享
  • 我如何过滤结果?
  • 查看docs,类似于:https://www.popads.net/api/campaign_list?key=9a790b65025e0aa449e60384a87b56e97c3ebf39?from=2020-07-01T00:00:00Z&amp;to=2020-08-01T00:00:00Z&amp;tz=Etc/GMT
  • 这不起作用...
  • 您要过滤什么?你有什么要求?他们的其余 API 处于早期阶段。您需要在最后执行操作

标签: php api curl get


【解决方案1】:

要列出最近 30 天内的记录,您可以过滤 curl 响应,如下所示

<?php
$url = 'https://www.popads.net/api/campaign_list?key=9a790b65025e0aa449e60384a87b56e97c3ebf39';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$resultArray = json_decode($result, true);
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Campaign Exclude App</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>

<body>
    <h1>Campaigns</h1><br>
    <input type="text" name="" id="">
    <input type="submit">
    <table class="table">
        <thead class="thead-dark">
            <tr>
                <th scope="col">Id</th>
                <th scope="col">Campaign Name</th>
                <th scope="col">CPA Goal</th>
                <th scope="col">Click Amount</th>
            </tr>
            <?php
            $today = date('Y-m-d h:i:s');
            $lastmonth = date('Y-m-d h:i:s', strtotime('-1 months', strtotime($today)));
            foreach ($resultArray['campaigns'] as $campaign) {
                if ($campaign['created'] > $lastmonth) {

            ?>
                    <tr>
                        <td scope="col"><?php echo $campaign['id']; ?> </td>
                        <td scope="col"><?php echo $campaign['name']; ?></td>
                        <td scope="col"><?php echo $campaign['xxxxxxx']; ?></td>
                        <td scope="col"><?php echo $campaign['xxxxxxx']; ?></td>
                    </tr>
            <?php }
            } ?>
        </thead>
    </table>


</body>

</html>

【讨论】:

  • 谢谢,但是如何设置七月的日期?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-27
  • 1970-01-01
  • 1970-01-01
  • 2013-03-22
  • 2017-07-14
  • 2013-09-01
  • 2018-07-27
相关资源
最近更新 更多