与Azure AD Graph API PHP示例的分页集成
我已成功连接到我的客户端目录,我能够从azure Active directory获取用户,但不是所有用户。我遵循了以下内容,但是本教程没有包括获取所有用户的示例,只包括默认页面大小100个用户 我知道skipToken(),但我不知道如何将其集成到我的循环中。下面是页面内容与Azure AD Graph API PHP示例的分页集成,php,azure-active-directory,Php,Azure Active Directory,我已成功连接到我的客户端目录,我能够从azure Active directory获取用户,但不是所有用户。我遵循了以下内容,但是本教程没有包括获取所有用户的示例,只包括默认页面大小100个用户 我知道skipToken(),但我不知道如何将其集成到我的循环中。下面是页面内容 用户的管理页面 用户的管理页面 显示名称 用户主体名称 对象ID 启用帐户 编辑链接 删除链接 基于您的代码,我在我这边做了一个演示。您可以参考以下代码 修改GraphServiceAccessHelper.php中
用户的管理页面
用户的管理页面
显示名称
用户主体名称
对象ID
启用帐户
编辑链接
删除链接
基于您的代码,我在我这边做了一个演示。您可以参考以下代码
修改GraphServiceAccessHelper.php中的getFeed函数
public static function getFeed($feedName){
// initiaze curl which is used to make the http request.
$ch = curl_init();
// Add authorization and other headers. Also set some common settings.
self::AddRequiredHeadersAndSettings($ch);
// set url
$feedURL = "https://graph.windows.net/".Settings::$appTenantDomainName."/".$feedName;
$feedURL = $feedURL."?".Settings::$apiVersion;
curl_setopt($ch, CURLOPT_URL, $feedURL);
//Enable fiddler to capture request
//curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
//curl_close($ch);
while(true){
$jsonOutput = json_decode($output);
$users = $jsonOutput->{'value'};
foreach ($users as $user){
$userArr[] = $user;
}
if(isset($jsonOutput->{'odata.nextLink'})){
$nextLink = $jsonOutput->{'odata.nextLink'};
$feedNextURL = "https://graph.windows.net/".Settings::$appTenantDomainName."/".$nextLink."&".Settings::$apiVersion;
curl_setopt($ch, CURLOPT_URL, $feedNextURL);
$output = curl_exec($ch);
}
else{
curl_close($ch);
break;
};
};
// There is a field for odata metadata that we ignore and just consume the value
return $userArr;
}
修改页面内容
<?php
$users = GraphServiceAccessHelper::getFeed('users');
$total = count($users);
$limit = 50;
$pages = ceil($total / $limit);
$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
'options' => array(
'default' => 1,
'min_range' => 1,
),
)));
$offset = ($page - 1) * $limit;
$start = $offset + 1;
$end = min(($offset + $limit), $total);
// The "back" link
$prevlink = ($page > 1) ? '<a href="?page=1" title="First page">«</a> <a href="?page=' . ($page - 1) . '" title="Previous page">‹</a>' : '<span class="disabled">«</span> <span class="disabled">‹</span>';
// The "forward" link
$nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next page">›</a> <a href="?page=' . $pages . '" title="Last page">»</a>' : '<span class="disabled">›</span> <span class="disabled">»</span>';
// Display the paging information
echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' of ', $pages, ' pages, displaying ', $start, '-', $end, ' of ', $total, ' results ', $nextlink, ' </p></div>';
$subUsers = array_slice($users, $offset, $limit);
foreach ($subUsers as $user){
if ($user->{'accountEnabled'} == 1)
{
$accountEnabled = 'True';
}
else
{
$accountEnabled = 'False';
}
$editLinkValue = "EditUser.php?id=".$user->objectId;
$deleteLinkValue = "DeleteUser.php?id=".$user->objectId;
echo('<tr><td>'. $user->{'displayName'}. '</td><td>'. $user->{'userPrincipalName'} .'</td>');
echo('<td>'. $user->{'objectId'}.'</td>');
echo ('<td>'. $accountEnabled.'</td>');
echo('<td>' .'<a href=\''.$editLinkValue.'\'>'. 'Edit User' . '</a></td><td>'
.'<a href=\''.$deleteLinkValue.'\'>'. 'Delete User' . '</a></td></tr>');
}
?>
测试结果:
非常感谢您的回复,我更改了代码以反映上述内容,但我收到以下错误:注意:未定义属性:stdClass::$value in D:\test\GraphServiceAccessHelper.php第26行警告:为foreach()提供的参数无效在第27行的D:\test\GraphServiceAccessHelper.php中,第26行和第27行如下:$users=$jsonOutput->{'value'};foreach($users作为$user){您能显示$output和$jsonOutput的值吗?