我正在创建一个UWP应用程序,想要使用Onedrive API,让用户可以将文件保存在他们的Onedrive帐户中,但是我不明白如何操作。到目前为止,我只成功了登录功能,我想要实现的功能有:
- 上传文件
- 下载文件
- 如果文件被修改,则同步更新
- 创建文件夹
- 删除文件
以下代码已经实现了登录功能,但我无法继续进行操作,该怎么办呢?
private async void btn_Login_Click(object sender, RoutedEventArgs e)
{
if (this.oneDriveClient == null)
{
try
{
// Setting up the client here, passing in our Client Id, Return Url,
// Scopes that we want permission to, and building a Web Broker to
// go do our authentication.
this.oneDriveClient = await OneDriveClient.GetAuthenticatedMicrosoftAccountClient(
clientId,
returnUrl,
scopes,
webAuthenticationUi: new WebAuthenticationBrokerWebAuthenticationUi());
// Show in text box that we are connected.
txtBox_Response.Text = "We are now connected";
// We are either just autheticated and connected or we already connected,
// either way we need the drive button now.
btn_GetDriveId.Visibility = Visibility.Visible;
}
catch (OneDriveException exception)
{
// Eating the authentication cancelled exceptions and resetting our client.
if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
{
if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
{
txtBox_Response.Text = "Authentication failed/cancelled, disposing of the client...";
((OneDriveClient)this.oneDriveClient).Dispose();
this.oneDriveClient = null;
}
else
{
// Or we failed due to someother reason, let get that exception printed out.
txtBox_Response.Text = exception.Error.ToString();
}
}
else
{
((OneDriveClient)this.oneDriveClient).Dispose();
this.oneDriveClient = null;
}
}
}
}
我在 Github 上创建了一个示例存储库:Onedrive Sync Files Sample。 我已经尝试过使用 Dropbox 和 Gdrive,但它们在 UWP 上的实现似乎要复杂得多,因此我选择了 OneDrive。感谢您提前给予任何帮助。