versium/reach-api-php-sdk

用于访问 Versium REACH API 的 PHP 客户端库。

v0.4.0 2023-06-20 17:40 UTC

This package is not auto-updated.

Last update: 2024-09-19 19:02:32 UTC


README

访问 Versium Reach APIs 的简化 PHP 接口

安装

从项目的根目录开始,使用 composer 从 packagist 安装 SDK。

composer require versium/reach-api-php-sdk

使用方法

  1. 使用 ReachClient
use Versium\Reach\ReachClient;
  1. 创建一个 ReachClient 实例,包含你的 API 密钥、可选的日志回调函数以及可选的每秒查询率限制。
$loggingFunction = function($msg) {
    //print out message for dev
    echo $msg;
};
$client = new ReachClient('you-api-key', $loggingFunction);

注意:记得在 Versium 客户服务增加你的速率限制时更新 $qps 值。

  1. 要向一组输入添加数据,请使用 append 函数。此函数返回一个 Generator,它产生包含 API 响应的数组。查看 API 文档 了解可用的数据工具和输出类型。
//call the contact API to append phones and emails 
$inputs = [
    [
        'first' => 'john',
        'last' => 'doe',
        'address' => '123 Trinity St',
        'city' => 'Redmond',
        'state' => 'WA',
        'zip' => '98052',
    ]
];

foreach ($client->append('contact', $inputs, ['email', 'phone']) as $results) {
    //filter out failed queries for processing later
    $failedResults = array_filter($results, function ($result) {
        return !$result->success;
    });
    
    //merge successful matches with inputs
    foreach ($results as $idx => $result) {
        if ($result->matchFound) {
            $inputs[$idx]['appendResults'] = $result->body->versium->results;
        }        
    }
}
  1. 要获取记录列表,请使用 listgen 函数。此函数返回一个单独的 APIResponse 对象。此对象包含用于遍历返回记录的 getRecordsFunc 属性。查看 API 文档 了解可用的数据工具和输出类型。
$result = $client->listgen('abm', ['domain' => ['versium.com']], ['abm_email', 'abm_online_audience']);

if ($result->success) {
    foreach (($result->getRecordsFunc)() as $record) {
        var_dump($record);
    }
}

返回结果

Both the append and listgen functions return one or more APIResponse objects. See the comments in the class for descriptions of its properties.

需要注意的事项

  • Reach APIs 的默认速率限制为每秒 20 次查询
  • 你必须有一个预配的 API 密钥才能使此功能正常工作。如果你不确定你的 API 密钥在哪里,请查看我们的 API 密钥文档