我只是在看Microsoft Graph API PHP SDK以获得大量资源,特别是Users。
查看SDK文档,有两种获取用户的方法,一种使用createRequest()
方法,另一种使用createCollectionRequest()
方法。
文档建议使用createCollectionRequest()
,然后执行while循环,array_merge
和getPage()
来创建数组。
while (!$docGrabber->isEnd()) {
$docs = array_merge($docs,$docGrabber->getPage());
}
问题是,我有大约50,000个用户,所以这种方法并不是特别有效。
我想最大的问题是,上面的示例(使用while循环)是避免使用API返回的@odata.nextLink
。
但是,如果我们实际上想使用它而不是返回单个数组中的每个记录,该怎么办?
谢谢
答案 0 :(得分:1)
除了使用getPage()和该示例之外,您还可以使用以下内容访问nextlink:
$url = "/users";
// Get the first page
$response = $graph->createCollectionRequest("GET", $url)
->setPageSize(50)
->execute();
if ($response->getNextLink())
{
$url = $response->getNextLink();
// TODO: remove https://graph.microsoft.com/v1.0 part of nextlink
} else {
// There are no more pages.
return null;
}
// get the next page, page size is already set in the next link
$response = $graph->createCollectionRequest("GET", $url)
->execute();