我试图使用Graph API在我的OneDrive应用的特殊应用文件夹中创建一个上传会话。我的应用程序具有以下权限:
Files.ReadWrite
Files.ReadWrite.AppFolder
offline_access
Run Code Online (Sandbox Code Playgroud)
请求看起来像这样
https://graph.microsoft.com/v1.0/users/xxxxxx96-2e02-4300-8ab0-a05d73xxxxxx/drive/special/approot:/documentname.docx:/createUploadSession
Run Code Online (Sandbox Code Playgroud)
给出以下错误:
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"request-id": "7447aa01-6685-4af0-998a-64abc9b14825",
"date": "2017-04-06T10:07:46"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在普通根文件夹上创建一个上传会话,而不会出现任何错误:
graph.microsoft.com/v1.0/users/xxxxxx96-2e02-4300-8ab0-a05d73xxxxxx/drive/root:/documentname.docx:/createUploadSession
Run Code Online (Sandbox Code Playgroud)
结果:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession",
"expirationDateTime": "2017-04-06T10:32:48.5252565Z",
"nextExpectedRanges": [
"0-"
],
"uploadUrl": "......."
}
Run Code Online (Sandbox Code Playgroud) 此代码有效
https://graph.microsoft.com:443/v1.0/me/drive/root?$filter=Size eq 0&$expand=children($select=id,folder,name,parentReference,cwebUrl)&$select=Id,folder,name,parentReference,children,webUrl
Run Code Online (Sandbox Code Playgroud)
我想在孩子里面过滤:
https://graph.microsoft.com:443/v1.0/me/drive/root?$filter=Size eq 0&$expand=children($select=id,folder,name,parentReference,cwebUrl&$filter=Size eq 0)&$select=Id,folder,name,parentReference,children,webUrl
Run Code Online (Sandbox Code Playgroud) 我正在与Microsoft Graph一起玩,以直接使用REST API(没有SDK)从我的应用程序访问Azure Active Directory。
根据文档,我应该能够从用户id
或userPrincipalName
使用中检索用户/users/{id | userPrincipalName}
。
这确实有效,但不适用于Guest用户。对于Guest用户userPrincipalName
来说就像是name_originaldomain#EXT#@mydomain.onmicrosoft.com
,并试图使用户获得结果404 Not Found
。
这是我当前正在使用的代码:
graphClient = new HttpClient();
graphClient.BaseAddress = new Uri("https://graph.microsoft.com/v1.0/");
graphClient.DefaultRequestHeaders.Add("Authorization", $"{token.TokenType} {token.AccessToken}");
HttpRequestMessage request = new HttpRequestMessage(
HttpMethod.Get,
$"users/{Uri.EscapeUriString(username)}"
);
HttpResponseMessage response = await graphClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsAsync<UserResult>();
}
// I am here with a 404
Run Code Online (Sandbox Code Playgroud)
我是否缺少某些东西或做错了什么?
我一直在尝试搜索我的SharePoint网站.我能够获得单个驱动器的结果:
xxx.sharepoint.com,xxxxxx-xxxx-xxxx-xxxx-xxxxxx,xxxxx-xxxx-xxxx-xxxx-xxxxxx/drives/xxxxxxxxx/search(q='{content}')
但如果我进行相同的搜索drive/root
,我不会得到任何结果:
xxx.sharepoint.com,xxxxxx-xxxx-xxxx-xxxx-xxxxxx,xxxxx-xxxx-xxxx-xxxx-xxxxxx/drive/root/search(q='{content}')
我们基本上希望在整个子网站上执行搜索.
我编写了一个能够与Exchange Online帐户通信的应用程序,我正在尝试测试以查看使其与在Hybrid中运行的内部部署帐户一起使用所需的步骤.
我有:
/PrepareAD
跑)/api/v2.0
和/autodiscover/autodiscover.json
不幸的是,我404
在尝试访问日历活动时遇到了问题:
curl -v -H 'Content-Type: application/json' -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFCSGg0a21TX2FLVDVYcmp6eFJBdEh6RE1mbEZNYTYwaktGRHRhUXp0ZGVkM2V6Z0ZfUzlLMjdDRmQxSHlfZGdRcnR6WlJBczRDV095R3E1Vl9OZW9MSFNKTGpzblNCSDNCQU9oQnBzU18wVmlBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoiU1NRZGhJMWNLdmhRRURTSnhFMmdHWXM0MFEwIiwia2lkIjoiU1NRZGhJMWNLdmhRRURTSnhFMmdHWXM0MFEwIn0.eyJhdWQiOiJodHRw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CcK7XfVWe-0wjrV6qBufd5z0hH_KpQLdzPtLOzSUGUAcXGa0mBPceTWULQvQ-LPcAJO57F0ir5k22fWzlkOfUxQb9eGWREUm1cAPWk3CPw" "https://graph.microsoft.com/v1.0/users/oq@healthcentrified.co.uk/calendar/events"
* Trying 137.116.241.64...
* Connected to graph.microsoft.com (137.116.241.64) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 592 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_256_CBC_SHA384
* server certificate verification OK
* server certificate status verification …
Run Code Online (Sandbox Code Playgroud) 尝试将文件上传到尚不存在的onedrive。我设法得到它来更新现有文件。但是似乎无法弄清楚如何创建一个全新的文件。我已经使用Microsoft.Graph
库完成了此操作。
以下是用于更新现有文件的代码:
public async Task<ActionResult> OneDriveUpload()
{
string token = await GetAccessToken();
if (string.IsNullOrEmpty(token))
{
// If there's no token in the session, redirect to Home
return Redirect("/");
}
GraphServiceClient client = new GraphServiceClient(
new DelegateAuthenticationProvider(
(requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", token);
return Task.FromResult(0);
}));
try
{
string path = @"C:/Users/user/Desktop/testUpload.xlsx";
byte[] data = System.IO.File.ReadAllBytes(path);
Stream stream = new MemoryStream(data);
// Line that updates the existing file
await client.Me.Drive.Items["55BBAC51A4E4017D!104"].Content.Request().PutAsync<DriveItem>(stream);
return View("Index");
}
catch (ServiceException ex)
{ …
Run Code Online (Sandbox Code Playgroud) 我们的应用程序通过对驱动器项执行Get调用来读取组驱动器内容.这曾经适用于内部成员和访客用户.它现在为内部成员工作,但不再为访客用户工作.以下是样本调用.
https://graph.microsoft.com/v1.0/drives/b!uey_5Lpf8Eu0-5HlGvJvFga89s_hTxNAg9kSsTlOBqajRqOF3ec-Rp6uqtbLNt4w/items/016GMDDVB74LSDDYRHHRHJ5KV5HHVXWQTT?$ select = webUrl,name
我们得到的回应是这样的
{
"error": {
"code": "unauthenticated",
"message": "Role Claim does not exist for Service Asserted App V1.",
"innerError": {
"request-id": "5ed31bd5-283c-4ce2-a6d6-a249f94ae9ee",
"date": "2018-06-27T09:39:01"
}
}
Run Code Online (Sandbox Code Playgroud)
以前工作得很好,最近Drive API有什么变化吗?我已检查更改的日志,但在上一版本中没有提到任何相关内容.
我正在使用Azure上托管的ASP.NET Core 2.0应用程序,并使用MSAL通过Microsoft对用户进行身份验证.我通过身份验证过程获取基本信息,如名称,用户名和组声明.但是,我想通过MS Graph访问一些其他信息,例如用户个人资料照片.初始身份验证和令牌获取平稳运行,并向https://graph.microsoft.com/beta/me
返回发送请求200 OK
.https://graph.microsoft.com/beta/me/photo/$value
然而,当试图打电话时,我得到一个401 - Unauthorized
回报.
我在这个问题上看到了其他几篇文章,但大多数人都认为开发人员忘记要求正确的同意,从错误的端点获取令牌或类似的问题.所有这些我都证实不是这样的.
我已经确认使用https://jwt.ms/在令牌中包含了适当的范围.我也尝试过要求更大的范围.目前我正在使用以下范围:openid profile User.ReadBasic.All User.Read.All User.ReadWrite Files.ReadWrite.All
.根据获取用户的beta参考,最少需要的权限是,User.Read
并根据获取照片的参考,最少需要的权限也是User.Read
.使用Graph Explorer我还确认我应该使用我的权限访问该照片,但是,我没有在我的个人资料上设置任何图片,因此它给了我一个404
回复.
我不知道为什么我无法访问个人资料照片,所以任何建议都非常感谢.如果您需要更多信息或详细信息,请告诉我们.如果相关,我有一个自定义中间件来处理读取用户信息的后验证过程,这也会对照片的MS Graph进行额外调用.
我也试过https://graph.microsoft.com/beta/users/{my-user-id}/photo/$value
产生相同的结果 - 图形浏览器中的404和我的代码中的401
这是我正在使用的代码.第一个代码段位于中间件中,该中间件将来自经过身份验证的用户的声明置于特定格式.我刚刚在返回时设置了一个断点并检查了响应对象.
public async Task GetUserPhotoAsync(string userid, HttpContext context)
{
HttpClient client = new HttpClient();
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var result = await new TokenHelper(_settings).GetAuthenticationAsync(userid, context, new string[] { "User.ReadBasic.All", "User.Read.All", "User.ReadWrite", "Files.ReadWrite.All" });
var …
Run Code Online (Sandbox Code Playgroud) 我将在Angular Web应用程序中使用Microsoft Graph API。
首先,我使用msal库进行连接。 当我尝试使用配置文件登录时,出现此错误
我已经按照官方git示例中提到的配置了我的应用
MsalModule.forRoot({
clientID: "Tenant ID",
authority: "https://login.microsoftonline.com/common/",
redirectUri: "http://localhost:4200/",
validateAuthority : true,
popUp: true
}),
Run Code Online (Sandbox Code Playgroud)
身份验证正在进行,我得到了令牌。
然后,当我进入主页时,我再次向Microsoft Graph API发出请求,以使用该令牌获取用户信息。
getProfile() {
let header= new Headers();
let tokenid= sessionStorage.getItem('msal.idtoken');
header.set('Authorization', 'Bearer ' + tokenid)
let url ="https://graph.microsoft.com/v1.0/me/"
return this.http.get(url,{headers:header});
}
Run Code Online (Sandbox Code Playgroud)
}
我收到响应401 Unauthorized错误:
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token validation failure.",
"innerError": {
"request-id": "xxxxxx",
"date": "2018-10-09T22:58:41"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么MG API不接受我的令牌,我是否使用了错误的授权URL?
更新:我知道实际上我得到的id_token与访问令牌不同。如何从MSAL库获取Access令牌以进行MS GRAPH API调用?:
javascript azure-active-directory microsoft-graph azure-ad-msal angular
我不是python的新手(也不是专业人士),但这是我第一次尝试这种方法。
我想使用python脚本将文件上传到OneDrive。听起来很简单吧?好吧,显然我可以处理的更多。
从到目前为止我所看到的,我正在使用的onedrive-sdk-python显然不再起作用了(来源:https : //github.com/OneDrive/onedrive-sdk-python/issues/119),因为它已经退役了。
我猜要使用的新SDK是适用于Microsoft Graph的SDK。但是github(https://github.com/MicrosoftArchive/msgraph-sdk-python)并未真正提到如何设置新的Oauth2身份验证,获取令牌并在python中使用客户端。身份验证部分中提到的链接对我不起作用,我收到如下错误消息:“ AADSTS900144:请求正文必须包含以下参数:'client_id'。”
我在stackoverflow上查找了类似的问题,但其中大多数是关于旧的onedrive-sdk的,而我能找到的最新版本已经快三个月了。那里的回应是它仍在开发中。
我想我一直遇到的问题都与Microsoft Graph仍在开发中有关,但是我想知道是否有人设法使其正常工作,以及他们是否可以为我指明正确的方向以进行身份验证设置并获得我开始将文件上传到OneDrive。
一些细节,以防万一:
非常感谢任何能为我指出正确方向的人:)
microsoft-graph ×10
onedrive ×5
c# ×2
angular ×1
api ×1
azure ×1
javascript ×1
odata ×1
office365 ×1
python ×1
restful-url ×1
sharepoint ×1