getresponse/sdk-php

适用于所有公开的GetResponse产品的SDK

3.0.0 2023-08-22 11:22 UTC

This package is auto-updated.

Last update: 2024-09-22 14:20:23 UTC


README

本文档涵盖了使用PHP SDK的基础知识。有关详细文档,请参阅docs目录中的资源。

GetResponse API DocsGetResponse API Reference中了解更多关于API的信息。

要求

  • PHP 7.3+

  • cURL

  • Composer或git

SDK安装

使用Composer

composer require getresponse/sdk-php

有关详细信息,请参阅https://composer.php.ac.cn

使用git

我们推荐使用composer安装。但是,您也可以通过克隆git项目来获取SDK PHP。


git clone https://github.com/GetResponse/sdk-php.git

版本在GitHub上可用: https://github.com/GetResponse/sdk-php/releases

创建客户端

要创建GetResponse客户端对象,请使用

<?php

use Getresponse\Sdk\GetresponseClientFactory;

$client = GetresponseClientFactory::createWithApiKey('my_api_key');

API_KEY应该在环境变量中定义。您应该在全局环境中、脚本的命令行或通过在框架启动时调用putenv()来定义它(我在哪里找到API密钥?

请参阅来自PHP SDKGetResponseClientFactory类以获取其他工厂。

企业用户

对于企业环境,请使用企业工厂之一,例如

<?php

use Getresponse\Sdk\GetresponseClientFactory;

$client = GetresponseClientFactory::createEnterprisePLWithApiKey('my_api_key', 'myexampledomain.com');

<?php

use Getresponse\Sdk\GetresponseClientFactory;

$client = GetresponseClientFactory::createEnterpriseUSWithApiKey('my_api_key', 'myexampledomain.com');

您必须提供在GetResponse中注册的域名。有关其他功能和授权方法,请参阅来自Getresponse\Sdk命名空间的GetResponseClientFactory类。

处理单个和多个操作

要发送单个操作(请求),您必须创建一个操作对象(可能包含参数)并通过定义的客户端发送。

示例

<?php

use Getresponse\Sdk\Operation\Campaigns\GetCampaigns\GetCampaigns; 

$campaignsOperation = new GetCampaigns();
$response = $client->call($campaignsOperation);

结果,您将获得一个响应对象。

您可以使用一个请求发送多个操作。这将加快并行处理操作的速度。请注意,将应用节流限制(在API限制和节流文档中了解更多信息)。

<?php

$operationsArray = array($operation1, $operation2, $operation3);
$responsesCollection = $client->callMany($operationsArray);

结果,您将获得一个响应集合。响应的顺序与数组中操作的顺序相同。

处理响应

要获取响应,请调用

<?php

$response = $client->call($campaignsOperation);

检查响应状态

要确定响应是否成功,请使用

<?php

$response->isSuccess();

要获取响应的HTTP状态,请使用

<?php

$response->getResponse()->getStatusCode();

响应数据

响应与PSR-7兼容。

示例

要从响应中获取数据(作为数组)

<?php

$response->getData();

要从响应中获取未处理的数据(以序列化的JSON格式)

<?php

$response->getResponse()->getBody()->getContents();

获取响应大小

<?php

$response->getResponse()->getBody()->getSize();

获取分页数据

<?php

$response->isPaginated();

$response->getPaginationValues();