OneDriveException”;resyncRequired”;分别同步来自两个子文件夹的更改时
本文关键字:两个 文件夹 resyncRequired 同步 OneDriveException | 更新日期: 2023-09-27 18:21:23
我在使用view.delta
从OneDrive同步更改时遇到问题(https://dev.onedrive.com/items/view_delta.htm)在两个不同的子文件夹中。我正在使用OneDrive API SDK(C#)。
我在OneDrive上的文件夹结构如下:
appFolder/data/folder1
appFolder/data/folder2
由于某些特定的原因,我想分别跟踪这两个子文件夹folder1
和folder2
上的更改,所以我使用两个不同的增量标记,每个子文件夹一个。
问题是,当其他子文件夹(如folder1)发生更改(添加/删除文件)时,对该文件夹调用"view.delta"可以正常工作,但使用自己的令牌对另一个子文件夹调用view.delta
会导致OneDriveException resyncRequired
,尽管该文件夹没有任何更改。
在OneDrive(而不是OneDrive for Business)上跟踪多个文件夹的更改是否存在一些问题/限制?
重现问题的示例代码:
static async Task Test(IOneDriveClient client)
{
var drive = client.Drive;
// get app folder
var appFolder = await drive.Special.AppRoot.Request().GetAsync();
// create data folder under the app folder
var dataFolder = await drive.Items[appFolder.Id].Children.Request().AddAsync(new Item { Name = "data", Folder = new Folder() });
// create two subfolders folder1 and folder2 under the data folder
var folder1 = await drive.Items[dataFolder.Id].Children.Request().AddAsync(new Item { Name = "folder1", Folder = new Folder() });
var folder2 = await drive.Items[dataFolder.Id].Children.Request().AddAsync(new Item { Name = "folder2", Folder = new Folder() });
// get initial token for the folder1
string token1 = null;
var changedItems1 = await drive.Items[folder1.Id].Delta(token1).Request().GetAsync();
token1 = changedItems1.Token;
// upload some test files under the folder1
var testFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///TestData/Document.txt"));
await UploadFileAsync(client, folder1, testFile, "file1");
await UploadFileAsync(client, folder1, testFile, "file2");
// get updated token for the folder1
changedItems1 = await drive.Items[folder1.Id].Delta(token1).Request().GetAsync();
token1 = changedItems1.Token;
// get initial token for the folder2
string token2 = null;
var changedItems2 = await drive.Items[folder2.Id].Delta(token2).Request().GetAsync();
token2 = changedItems2.Token;
// now make some change under the folder1 (upload, delete)
await UploadFileAsync(client, folder1, testFile, "file3");
// get updated token for the folder1, this works ok
changedItems1 = await drive.Items[folder1.Id].Delta(token1).Request().GetAsync();
token1 = changedItems1.Token;
try
{
// try to get changes for the folder2, this throws OneDriveException
changedItems2 = await drive.Items[folder2.Id].Delta(token2).Request().GetAsync();
token2 = changedItems2.Token;
}
catch (Exception ex)
{
// Exception is thrown with the following message:
// "Resync required. Upload any local items that the service did not return, and upload any files that differ from the server's version (keeping both copies if you're not sure which one is more up-to-date)."
}
}
static async Task UploadFileAsync(IOneDriveClient client, Item destinationFolder, IStorageFile file, string fileName)
{
using (var stream = await file.OpenStreamForReadAsync())
{
var item = await client.Drive.Items[destinationFolder.Id].ItemWithPath(fileName).Content.Request().PutAsync<Item>(stream);
}
}
这是服务的问题,而不是您如何使用它的问题。我们现在正在努力解决它-您可以使用此链接来跟踪我们的进度。
谢谢你让我们知道!