[英]Microsoft Graph API : Get Tasks of users in a group with PHP
[英]Creating users using the Microsoft Graph API (PHP)
我正在嘗試構建一個與Microsoft Graph API集成的應用程序。
我在 Azure 中有一個管理員帳戶,並通過門戶設置了一個新應用程序。 我已經下載並安裝了PHP SDK ,並設法設置了所有內容,以便成功獲得用戶。
我可以登錄應用程序並授予使用我的信息的權限(我請求的權限是Directory.ReadWrite.All
,但即使只是請求User.ReadWrite.All
對我不起作用),但是,我的問題似乎是我無法訪問其他用戶。
以下僅返回我自己的用戶:
$graph = new Graph();
$graph->setAccessToken('/* SOMETOKEN */');
$users = $graph->createRequest('GET', '/users')
->setReturnType(User::class)
->execute();
發布新用戶返回 404 錯誤:
$newUser = new User();
$newUser->setAccountEnabled(true);
$newUser->setGivenName('first_name');
$newUser->setSurname('last_name');
$newUser->setUserPrincipalName('some.email@address.com');
$password = new PasswordProfile();
$password->setPassword('some_password');
$newUser->setPasswordProfile($password);
$user = $graph->createRequest('POST', '/users')
->attachBody($newUser)
->execute();
回報:
{
"error": {
"code": "",
"message": "No HTTP resource was found that matches the request URI 'https://outlook.office365.com:444/profile/v1.0/users('CID:a8ef4446a149de4d')/profile?api-version=AGSV1-internal'.",
"innerError": {
"date": "/* timestamp */",
"request-id": "/* an id */",
"client-request-id": "/* an id */"
}
}
}
即使嘗試使用 Microsoft 的Graph Explorer也會遇到同樣的錯誤。
我是否認為這可能是帳戶設置問題?
這是 Graph Explorer 返回的錯誤消息
{
"error": {
"code": "",
"message": "No HTTP resource was found that matches the request URI 'https://outlook.office365.com:444/profile/v1.0/users('CID:a8ef4446a149de4d')/profile?api-version=AGSV1-internal'.",
"innerError": {
"date": "2020-11-30T16:51:41",
"request-id": "743030b4-8835-4a9f-9e3e-d35919a1c289",
"client-request-id": "c40cd440-d873-ba38-dce7-8669bc561e64"
}
}
}
我已經解決了這個問題。
問題出在許可請求中。 我的應用程序設置為允許個人帳戶以及工作/學校帳戶。 使用個人帳戶登錄時,我的用戶無法授予*.ReadWrite
或*.All
權限。
當我從身份驗證請求中獲取令牌時,它只有User.Read
權限。
User.Read.All
的權限現在應該可以工作了/users
端點應該返回所有用戶為了讓寫入工作,我需要注冊一個合作伙伴中心 MPN ID並將其與我在 Azure 中的應用程序相關聯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.