如何使用结果的 `nextLink` 属性?
How do I use the `nextLink` property of a result?
查询结果对象 returns nextLink
设置为 URL 作为下一页结果的字符串或 null,具体取决于是否有另一页当前的一个。文档对此非常清楚,但是其中没有关于如何获取 link 并为下一页发出另一个请求的任何内容。
我一直在挖掘源代码,只发现它似乎真的没有任何方法可以利用这个值,除了一个布尔值告诉我还有更多。留下这样一个明显松散的结局,即使在测试版 API 中,听起来也不像 Google,所以我一定是遗漏了什么。
根据我的代码设置方式,我不能只重用生成初始请求的请求数据。我有单独的逻辑来发出初始请求并将结果集解析为可用形式。那,并且知道 link 被公开,就好像它是要被使用的暗示,有一种比修改初始请求更干净的方法。只是,我该怎么做?
我有一些似乎有用的东西。重要的一点在底部,我在那里使用 nextLink
并使用这些部分进行新的查询。这并不理想,但它比尝试手动 cURL 效果更好,正如网上其他所有内容似乎所暗示的那样。 Google_Service_Analytics_GaData
当然,会因使用的服务而异。
do {
$rows = $results->getRows();
foreach ($rows as $row) {
$record = array();
foreach ($row as $i => $field) {
$name = $headers[$i]->name;
switch($headers[$i]->dataType) {
case 'FLOAT':
$record[$name] = (float) $field;
break;
case 'INTEGER':
$record[$name] = (int) $field;
break;
default:
$record[$name] = (string) $field;
}
}
$records[] = $record;
};
$nextLink = $results->getNextLink();
if ($nextLink) {
/* The GA API doesn't have anything to actually USE The link
* they so helpfully supply, so we have to disassemble it and
* make a new query off of it. Internally,
* $this->gaService->data_ga calls $this->gaService->call.
* These are on `Google_Service_Analytics_DataGa_Resource` and
* `Google_Service_Resource`, respectively.
*/
$options = [];
parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);
$results = $this->gaService->data_ga->call('get', [$options], "Google_Service_Analytics_GaData");
}
} while ($nextLink);
查询结果对象 returns nextLink
设置为 URL 作为下一页结果的字符串或 null,具体取决于是否有另一页当前的一个。文档对此非常清楚,但是其中没有关于如何获取 link 并为下一页发出另一个请求的任何内容。
我一直在挖掘源代码,只发现它似乎真的没有任何方法可以利用这个值,除了一个布尔值告诉我还有更多。留下这样一个明显松散的结局,即使在测试版 API 中,听起来也不像 Google,所以我一定是遗漏了什么。
根据我的代码设置方式,我不能只重用生成初始请求的请求数据。我有单独的逻辑来发出初始请求并将结果集解析为可用形式。那,并且知道 link 被公开,就好像它是要被使用的暗示,有一种比修改初始请求更干净的方法。只是,我该怎么做?
我有一些似乎有用的东西。重要的一点在底部,我在那里使用 nextLink
并使用这些部分进行新的查询。这并不理想,但它比尝试手动 cURL 效果更好,正如网上其他所有内容似乎所暗示的那样。 Google_Service_Analytics_GaData
当然,会因使用的服务而异。
do {
$rows = $results->getRows();
foreach ($rows as $row) {
$record = array();
foreach ($row as $i => $field) {
$name = $headers[$i]->name;
switch($headers[$i]->dataType) {
case 'FLOAT':
$record[$name] = (float) $field;
break;
case 'INTEGER':
$record[$name] = (int) $field;
break;
default:
$record[$name] = (string) $field;
}
}
$records[] = $record;
};
$nextLink = $results->getNextLink();
if ($nextLink) {
/* The GA API doesn't have anything to actually USE The link
* they so helpfully supply, so we have to disassemble it and
* make a new query off of it. Internally,
* $this->gaService->data_ga calls $this->gaService->call.
* These are on `Google_Service_Analytics_DataGa_Resource` and
* `Google_Service_Resource`, respectively.
*/
$options = [];
parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);
$results = $this->gaService->data_ga->call('get', [$options], "Google_Service_Analytics_GaData");
}
} while ($nextLink);