dockflow / hubspot-php
此包已被放弃,不再维护。没有建议的替代包。
HubSpot PHP API 客户端
v2.0.8
2020-09-14 15:14 UTC
Requires
- php: >=7.0
- ext-json: *
- guzzlehttp/guzzle: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- phpspec/phpspec: ^3.4
- phpunit/phpunit: ~5.0
- dev-master
- v2.0.8
- 2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- 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-dockflow
This package is auto-updated.
Last update: 2020-12-14 16:12:40 UTC
README
Hubspot 是一款营销、销售和服务软件,可以帮助您的业务在没有妥协的情况下增长。因为“对业务好”也应该意味着“对客户好”。
设置
Composer
composer require "hubspot/hubspot-php"
示例应用
快速入门
使用工厂的示例
以下所有示例都假设这一步骤。
$hubspot = SevenShores\Hubspot\Factory::create('api-key'); // OR create with OAuth2 access token $hubspot = SevenShores\Hubspot\Factory::createWithOAuth2Token('access-token'); // OR instantiate by passing a configuration array. // The only required value is the 'key' $hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', 'oauth2' => 'false', // default ]);
有关 API 密钥的更多信息,请参阅此处,有关访问令牌的更多信息,请参阅此处
注意:您可以通过将以下选项传递给客户端创建例程来防止此包提供的任何错误处理:(也适用于 Factory::create()
和 Factory::createWithOAuth2Token()
)
$hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', ], 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。
API 客户端附带用于实现速率和并发限制的中间件。
它提供了对失败请求进行重试的能力,请求状态为 429 或 500。您可以在此处了解更多关于 HubSpot API 速率限制的信息。
$handlerStack = \GuzzleHttp\HandlerStack::create(); $handlerStack->push( \SevenShores\Hubspot\RetryMiddlewareFactory::createRateLimitMiddleware( \SevenShores\Hubspot\Delay::getConstantDelayFunction() ) ); $handlerStack->push( \SevenShores\Hubspot\RetryMiddlewareFactory::createInternalErrorsMiddleware( \SevenShores\Hubspot\Delay::getExponentialDelayFunction(2) ) ); $guzzleClient = new \GuzzleHttp\Client(['handler' => $handlerStack]); $config = [ 'key' => 'demo', 'oauth2' => false, ]; $hubspot = new \SevenShores\Hubspot\Factory(config, new \SevenShores\Hubspot\Http\Client($config, guzzleClient));
获取单个联系信息
$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) { // }
使用内置工具的示例
<?php require 'vendor/autoload.php'; use SevenShores\Hubspot\Utils\OAuth2; $authUrl = OAuth2::getAuthUrl( 'clientId', 'http://localhost/callaback.php', 'contacts' );
或使用工厂
<?php require 'vendor/autoload.php'; use SevenShores\Hubspot\Utils; $authUrl = Utils::getFactory()->oAuth2()->getAuthUrl( 'clientId', 'http://localhost/callaback.php', 'contacts' );
状态
如果您看到了您想要但没有计划的内容,请提出一个 问题,我有很大可能会添加它。
- 分析 API
- 日历 API :更新
- 公司 API :更新
- 公司属性 API :更新
- 联系信息 API :更新
- 联系列表 API :更新
- 联系属性 API :更新
- Conversations 实时聊天小部件 API(前端)
- CMS 博客 API(博客):更新
- CMS 博客作者 API(BlogAuthors):更新
- 内容管理系统博客评论API(评论)
- 内容管理系统博客帖子API(博客帖子)
- 内容管理系统博客主题API(博客主题)
- 内容管理系统域名API
- 内容管理系统文件API(文件)
- 内容管理系统HubDB API(HubDB): 已更新
- 内容管理系统布局API
- 内容管理系统页面发布API(页面)
- 内容管理系统网站地图
- 内容管理系统网站搜索API
- 内容管理系统模板API
- 内容管理系统URL映射API
- 客户关系管理关联API
- 客户关系管理扩展API
- 客户关系管理对象属性API(对象属性)🆕
- 客户关系管理管道API(CrmPipelines)
- 交易API
- 交易管道API : 已弃用
- 交易属性API : 已更新
- 电子商务桥接API : 已更新
- 电子邮件订阅API : 已更新
- 电子邮件事件API : 已更新
- 参与API
- 活动API
- 表单API : 已更新
- 行项目API 🆕
- 营销电子邮件API
- 所有者API : 已更新
- 产品API 🆕
- 社交媒体API
- 票据API
- 时间轴API : 已更新
- 跟踪代码API
- 交易电子邮件API
- 工作流API : 已更新
- Webhooks API