ryanwinchester / hubspot-php
v1.2.2
2019-11-05 08:53 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master@dev
- phpspec/phpspec: ~2.0
- phpunit/phpunit: ~4.0
- dev-master
- 2.0.x-dev
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-rc.4
- v1.0.0-rc.3
- v1.0.0-rc.2
- v1.0.0-rc.1
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9
- v0.2
- v0.1.1
- v0.1.0
- dev-feature/additionTimelineRequests
- dev-php54-guzzle5
- dev-php53
- dev-develop
This package is auto-updated.
Last update: 2019-11-05 18:40:55 UTC
README
HubSpot API 客户端。这是我对 HubSpot/haPihP. 客户端的完美功能的包装的后续版本。然而,这是一个全新的重写,并包括了一些新的 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) 🆕
- 时间轴 🆕
- 工作流