fotografde / hubspot-php
HubSpot PHP API 客户端
1.1
2022-08-16 09:42 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0|^7.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master@dev
- phpspec/phpspec: ~2.0
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-16 15:03:09 UTC
README
Hubspot API 客户端。这是对 HubSpot/haPihP. client. 的功能完善的包装器的后续作品。然而,这是一个完全重写的版本,并包括一些新的 COS/v2 端点。
设置
Composer
composer require "ryanwinchester/hubspot-php:~1.0"
快速入门
使用工厂方法的示例
以下所有示例都假设这一步。
$hubspot = SevenShores\Hubspot\Factory::create('api-key'); // OR instantiate by passing a configuration array. // The only required value is the 'key' $hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', 'oauth' => false, // default 'base_url' => 'https://api.hubapi.com' // default ]);
注意:您可以通过将以下选项传递到客户端创建例程中来防止此包提供的任何错误处理:(也适用于 Factory::create()
和 Factory::createWithToken()
)
$hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', 'oauth' => false, // default 'base_url' => 'https://api.hubapi.com' // default ], null, [ 'http_errors' => false // pass any Guzzle related option to any request, e.g. throw no exceptions ], false // return Guzzle Response object for any ->request(*) call );
将 http_errors
设置为 false,您将不会收到任何异常,但只有纯响应。有关可能的选项,请参阅 http://docs.guzzlephp.org/en/latest/request-options.html。
获取单个联系人
$contact = $hubspot->contacts()->getByEmail("test@hubspot.com"); echo $contact->properties->email->value;
遍历所有联系人
// Get an array of 10 contacts // getting only the firstname and lastname properties // and set the offset to 123456 $response = $hubspot->contacts()->all([ 'count' => 10, 'property' => ['firstname', 'lastname'], 'vidOffset' => 123456, ]);
处理数据非常简单!
foreach ($response->contacts as $contact) { echo sprintf( "Contact name is %s %s." . PHP_EOL, $contact->properties->firstname->value, $contact->properties->lastname->value ); } // Info for pagination echo $response->{'has-more'}; echo $response->{'vid-offset'};
或者如果您喜欢使用数组访问?
foreach ($response['contacts'] as $contact) { echo sprintf( "Contact name is %s %s." . PHP_EOL, $contact['properties']['firstname']['value'], $contact['properties']['lastname']['value'] ); } // Info for pagination echo $response['has-more']; echo $response['vid-offset'];
现在使用实现 PSR-7 ResponseInterface 的响应方法
$response->getStatusCode() // 200; $response->getReasonPhrase() // 'OK'; // etc...
无工厂示例
<?php require 'vendor/autoload.php'; use SevenShores\Hubspot\Http\Client; use SevenShores\Hubspot\Resources\Contacts; $client = new Client(['key' => 'demo']); $contacts = new Contacts($client); $response = $contacts->all(); foreach ($response->contacts as $contact) { // }
状态
如果您看到不计划出现但希望看到的内容,请创建一个 问题,我有很大机会会添加它。
- 博客(COS)🆕
- 博客作者(COS)🆕
- 博客文章(COS)🆕
- 博客主题(COS)🆕
- 公司 🆕
- 公司属性 🆕
- 联系人
- 联系人列表
- 联系人属性
- 交易 🆕
- 电子邮件 🆕
- 电子邮件事件 🆕
- 参与度
- 事件(企业)🆕
- 文件(COS)🆕
- 表单
- 关键词
- 所有者
- 页面发布(COS)🆕
- 社交媒体
- 模板(COS)🆕
- 时间线 🆕
- 工作流