从 Hubspot API 获取完整的联系人列表 [英] Getting full list of contacts from Hubspot API
问题描述
Hubspot 的 API 允许您检索联系人列表,但每次调用最多只允许 100 个.
Hubspot's API allows you retrieve a list of contacts, however it only allows a max of 100 per call.
我通过这个电话来做到这一点:
I do that with this call:
$contacts_batch1 = $contacts->get_all_contacts(array( 'count' => '100'));
然后如果我想获得下一个 100 我这样做:
And then if I want to get the next 100 I do this:
$offset1 = $contacts_batch1->{'vid-offset'};
$contacts_batch2 = $contacts->get_all_contacts(array('count' => '100', 'vidOffset'=>$offset1));
我正在尝试获取所有联系人,而不必每次想要下一个 100 时都创建一个新变量.我的第一个问题是我将如何获取最后一组的 vid 偏移量,然后如何获取我将其作为参数自动放入下一个变量中.
I am trying to get all the contacts without having to create a new variable each time I want the next 100. My first question would be how would I go about getting the vid-offset of the last set, and then how would I put that as a parameter into the next variable automatically.
推荐答案
以下是使用 HubSpot 的 API 将所有联系人放入一个数组的示例.
Here's an example of getting all contacts into one array using HubSpot's API.
<?php
require "haPiHP/class.contacts.php";
require "haPiHP/class.exception.php";
define("HUBSPOT_API_KEY", "<YOUR API KEY HERE>");
$contacts = new HubSpot_Contacts(HUBSPOT_API_KEY);
$all_contacts = array();
do
{
$params = array("count" => 100);
if (isset($vidOffset))
{
$params["vidOffset"] = $vidOffset;
}
echo "count=" . $params["count"] . (isset($params["vidOffset"]) ? ", vidOffset=" . $params["vidOffset"] : "") . "\n";
$some_contacts = $contacts->get_all_contacts($params);
if ($some_contacts !== NULL)
{
$all_contacts = array_merge($all_contacts, $some_contacts->contacts);
}
else
{
break;
}
$vidOffset = $some_contacts->{'vid-offset'};
} while ($some_contacts->{'has-more'});
echo "Received " . count($all_contacts) . " contacts.\n";
?>
这篇关于从 Hubspot API 获取完整的联系人列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!