ryanwinchester/hubspot-php

该包已被废弃,不再维护。作者建议使用hubspot/hubspot-php包。

HubSpot PHP API 客户端

v1.2.2 2019-11-05 08:53 UTC

README

Version Total Downloads License

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) 🆕
  • 时间轴 🆕
  • 工作流