braze / sdk
使用 Braze API 跟踪用户、发送消息、导出数据等。
2.2.0
2024-07-30 23:48 UTC
Requires
- php: >=8.0
- jane-php/open-api-runtime: 7.8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.22
- jane-php/open-api-3: 7.8.1
- nyholm/psr7: ^1.8
- pestphp/pest: ^1.23 || ^2.0
- php-http/guzzle7-adapter: ^1.0
- symfony/http-kernel: ^6.4
README
PHP 库,用于 Braze。代码使用 OpenAPI 规范 生成。
要求
版本
PHP >=8.0
API URL
使用您在仪表板登录时分配给您的账户的 REST 端点
API Key
您可以在 Braze 仪表板中创建 API 密钥
安装
使用 Composer 安装
composer require braze/sdk
使用 Composer 的 自动加载
require_once 'vendor/autoload.php';
使用方法
实例化客户端
use Braze\Braze; $braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY'); $client = $braze->client;
或创建自定义客户端
use Braze\Client; $httpClient = \Http\Discovery\Psr18ClientDiscovery::find(); $uri = \Http\Discovery\Psr17FactoryDiscovery::findUriFactory()->createUri('YOUR_API_URL'); $bearer = new \Http\Message\Authentication\Bearer('YOUR_API_KEY'); $plugins = [ new \Http\Client\Common\Plugin\AddHostPlugin($uri), new \Http\Client\Common\Plugin\AuthenticationPlugin($bearer), ]; $httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins); $client = Client::create($httpClient);
向用户发送消息
use Braze\Braze; use Braze\Model\MessagesSendPostBody; $braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY'); $braze->client->postMessagesSend(new MessagesSendPostBody([ 'external_user_ids' => ['your_external_user_id'], 'messages' => [ 'email' => [ 'app_id' => 'your_app_id', 'from' => 'Company <company@example.com>', 'email_template_id' => 'your_email_template_id', ], ], ]));
处理 API 错误
use Braze\Braze; $braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY'); try { $braze->client->getCatalog(); } catch (Throwable $exception) { echo $exception->getMessage(); echo $exception->getCode(); }
脚本
composer build
生成代码
composer build
composer clean
删除 lib/
目录
composer clean
composer test
运行测试
composer test
关于此包
此包由 Jane 自动生成。