exads/exads-api-client-php

v1.3.1 2019-04-15 17:32 UTC

This package is auto-updated.

Last update: 2024-09-15 02:01:09 UTC


README

一个简单的面向对象的 Exads API 包装器,用 PHP5 编写。

参见 Exads API 的文档。

功能

  • 遵循 PSR-0 规范和编码标准:易于自动加载
  • API 入口点实现状态
  • 活动
  • 收集
  • 登录
  • 支付
  • 网站
  • 统计
  • 用户
  • 区域

要求

  • PHP >= 5.4
  • PHP cURL 扩展
  • PHP JSON 扩展
  • PHPUnit >= 4.0(可选)以运行测试套件

安装

Composer

Composer 用户只需在项目根目录中运行

$ composer require exads/exads-api-client-php

。为了使用库,请在使用 Exads 类的脚本中包含 Composer 的 vendor/autoload.php

例如,

<?php

// This file is generated by Composer
require_once 'vendor/autoload.php';

$client = new Exads\Client('https://api.exoclick.com/v2/');
// ...

独立(不推荐)

库附带了基本的 autoload.php 文件,允许您在不使用 Composer 的情况下使用它。请参阅最新版本:https://github.com/EXADS/exads-api-client-php/releases

$ mkdir vendor
$ wget -q https://github.com/EXADS/exads-api-client-php/archive/v1.3.0.tar.gz
$ tar -xf v1.3.0.tar.gz -C vendor/
$ rm v1.3.0.tar.gz

然后您的引导脚本应如下所示

<?php

// This file ships with the library
require 'vendor/exads-api-client-php-1.2.2/lib/autoload.php';

$client = new Exads\Client('https://api.exoclick.com/v2/');

使用 exads-api-client-php 客户端的简单示例

<?php

require_once 'vendor/autoload.php';

try {
    $client = new Exads\Client('https://api.exoclick.com/v2/');

    // There are two authentication methods:
    // a. with username and password
    $sessionToken = $client->login->getToken('username', 'password');
    // b. with APItoken
    // $sessionToken = $client->login->getToken('APItoken');

    $client->setApiToken($sessionToken);
    // ...
    $campaigns = $client->campaigns->all();
    // ...
} catch (\Exception $e) {
    die($e->getMessage());
}

有关可用方法的完整列表,请参阅 test/Exads/Tests/UrlsTest.php

将参数传递到端点

如 API 文档中所述,大多数 GET 入口点接受参数以过滤调用的结果。特别是对于长集合,您应使用 offset 对 API 返回的结果进行分页(一次调用不能获取超过 50 个元素,这时就需要 offset)。以下是一些示例

<?php
...

// Getting the total number of carriers
$client->collections->carriers(array('count' => true));

// Getting the carriers 50..100
$client->collections->carriers(array('offset' => 50));

请参阅文档以获取每个入口点允许的完整参数列表。