问题
The .AddAsync(driveItem)
in the following code never returns. Could anyone shed some light on this?
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(App.ClientId)
.Build();
DeviceCodeProvider authProvider = new DeviceCodeProvider(
publicClientApplication,
new string[] { "Files.ReadWrite.All" });
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
DriveItem driveItem = new DriveItem
{
Name = "Foo",
Folder = new Folder { },
AdditionalData = new Dictionary<string, object>()
{ { "@microsoft.graph.conflictBehavior", "fail" }
}
};
await graphClient
.Me
.Drive
.Root
.Children
.Request()
.AddAsync(driveItem);
[Edit 1]
I have tried folder names other than "Foo", tried names of existing or non-existing folders to no avail.
I also tried "rename" instead of "fail" for "@microsoft.graph.conflictBehavior" to no avail.
I also tried without AdditionalData to no avail.
[Edit 2]
I decided to wait for the method to return for a while (more than 10 minutes), and it finally threw an exception:
Code: generalException Message: An error occurred sending the request.
Source "Microsoft.Graph.Core"
at Microsoft.Graph.HttpProvider.<SendRequestAsync>d__19.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__35.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendAsync>d__31`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Inner Exception:
Code: generalException Message: Unexpected exception occured while authenticating the request.
at Microsoft.Graph.Auth.DeviceCodeProvider.<GetNewAccessTokenAsync>d__14.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.Auth.DeviceCodeProvider.<AuthenticateRequestAsync>d__13.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.AuthenticationHandler.<SendAsync>d__16.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__62.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.HttpProvider.<SendRequestAsync>d__19.MoveNext()
[Edit 3]
The following code has exactly the same problem:
IDriveItemChildrenCollectionPage children = await graphClient.Me.Drive.Root.Children
.Request()
.GetAsync();
This looks like a general problem for the Graph SDK.
[Edit 4]
I played the app registration of Azure Active Directory, and got the following most inner exception:
AADSTS70000: The provided value for the input parameter 'device_code' is not valid.
Trace ID: 7067d5e9-d811-49ed-9b8b-7a0b9a0c4c00
Correlation ID: a4faa514-debc-47dc-8ef3-0b9853949e28
Timestamp: 2020-01-11 06:47:36Z
Again, I have to wait for more than 10 minutes for the exception to be thrown.
[Edit 5] Not sure why exactly the same calls using Microsoft.Toolkit.Graph.Controls work perfectly.
await provider.Graph.Me.Drive.Root.Children
.Request()
.AddAsync(driveItem);
回答1:
I'm not sure why this isn't returning, but Camera Roll
is one of the special folders (and therefore a reserved folder name). There are a small number of these that get automatically generated either when the Drive
is provisioned or when a specific service connects for the first time (i.e. "Camera Roll" is created by the OneDrive app):
- Documents
- Photos
- Camera Roll
- App Root
- Music
In order to retrieve the Camera Roll folder, you request it by it's "id":
GET /me/drive/special/cameraroll
来源:https://stackoverflow.com/questions/59686896/addasyncdriveitem-does-not-return