【发布时间】:2019-09-20 05:00:14
【问题描述】:
我有一个应用程序可以处理大量数据并生成一些结果。目前该应用程序通过电子邮件发送结果,但这可能很麻烦并且电子邮件可能会变得太大,因此我希望应用程序将结果存储到共享的 OneDrive 文件夹中。应用无需用户交互即可运行。
我一直在研究 Microsoft.Graph sdk 的多个示例。我已经能够使用应用程序和 ConfidentialClient 工作流程进行身份验证,但我不确定如何在 OneDrive 中查找/访问共享目录。目前,仅根驱动器请求不会返回任何子驱动器或任何有用的东西。当我使用 API 以我的用户身份登录时,我可以访问共享驱动器,但那是为我的用户使用共享链接。我是否需要以某种方式为应用程序生成共享链接或不绑定到用户?还是有其他方法可以找到共享驱动器?
这是创建我的 GraphServiceClient 的代码:
public static GraphServiceClient GetAuthenticatedClient()
{
if (graphClient == null)
{
ConfidentialClientApp = ConfidentialClientApplicationBuilder.Create(clientId).WithTenantId(FormBrowser.MsaTenantId).WithClientSecret(FormBrowser.MsaClientSecret).Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(ConfidentialClientApp);
graphClient = new GraphServiceClient(authProvider);
}
return graphClient;
}
然后我尝试了其中一些不同的调用,以确保它正确地进行身份验证:
//var shares = await this.graphClient.Shares[encodedUrl].Root.Request().Expand(expandValue).GetAsync();
//ProcessFolder(shares);
var drive = graphClient.Drive.Request().GetAsync();
ProcessFolder(await this.graphClient.Drive.Root.Request().Expand(expandValue).GetAsync());
这是来自 Drive.Root 请求的 JSON 响应示例:
{
"createdDateTime": "2013-11-07T19:59:00+00:00",
"lastModifiedDateTime": "2019-09-15T02:12:23+00:00",
"name": "root",
"webUrl": "https://<company>.sharepoint.com/Documents",
"fileSystemInfo": {
"createdDateTime": "2013-11-07T19:59:00+00:00",
"lastModifiedDateTime": "2019-09-15T02:12:23+00:00"
},
"folder": {
"childCount": 0
},
"parentReference": {
"driveId": "<stuff>",
"driveType": "documentLibrary"
},
"root": {
},
"size": 0,
"children": [
],
"thumbnails": [
],
"id": "<stuff>",
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drive/root(thumbnails(),children(thumbnails()))/$entity",
"children@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drive/root/children(thumbnails())",
"thumbnails@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drive/root/thumbnails",
"responseHeaders": {
"Transfer-Encoding": [
"chunked"
],
"Vary": [
"Accept-Encoding"
],
"request-id": [
"<id>"
],
"client-request-id": [
"<id>"
],
"x-ms-ags-diagnostic": [
"{\"ServerInfo\":{\"DataCenter\":\"North Central US\",\"Slice\":\"SliceC\",\"Ring\":\"1\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"<stuff>\",\"ADSiteName\":\"<stuff>\"}}"
],
"OData-Version": [
"4.0"
],
"Duration": [
"259.0577"
],
"Strict-Transport-Security": [
"max-age=31536000"
],
"Cache-Control": [
"private"
],
"Date": [
"Thu, 19 Sep 2019 14:06:27 GMT"
]
},
"statusCode": "OK"
}
【问题讨论】:
标签: c# microsoft-graph-api onedrive microsoft-graph-sdks