c# - 尝试从 UWP 访问 OneDrive 根目录时出错

标签 c# win-universal-app uwp onedrive

当我运行以下代码时,我在调用请求时收到异常(消息:必须经过身份验证才能使用“/drive”语法):

private async Task<Item> GetRoot()
{
    var driveClient = 
        await OneDriveClientExtensions.GetAuthenticatedUniversalClient(
            new string[] { "files.readwrite", "offline_access" }
            );

    if (!driveClient.IsAuthenticated) return null;

    var itemRequest = driveClient.Drive.Root.Request();

    return await itemRequest.GetAsync();
}

我尝试使用 IHttpProvider 的覆盖进行调试,我看到 GET 请求已发送到 https://api.onedrive.com/v1.0/drive/root有两个 header X-RequestStatsAuthorization 以及正确的 token 。

我还在https://account.live.com/consent/Manage中检查了对该应用程序的同意我看到“访问 OneDrive 文件”和“随时访问你的信息”权限。

我可能错过了一些基本的东西。请指教。

谢谢

最佳答案

I also checked consent for the app in https://account.live.com/consent/Manage and I see "Access OneDrive files" and "Access your info anytime" permissions.

这是一个文档问题,文件。* 范围未正确注册 OneDrive Personal。

The document恢复到以前的版本,请使用onedrive.readwrite范围来确保您的应用按预期工作。

参见this issue在 onedrive-api-docs 存储库中

It appears that the files.* scopes are not properly registered for OneDrive Personal. I've reverted the documentation to indicate you should use the onedrive.* scopes for OneDrive Personal. Please use the onedrive.readwrite scope to ensure your app works as expected.

关于c# - 尝试从 UWP 访问 OneDrive 根目录时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37374294/

相关文章:

c# - C#中的多重继承

mvvm - 如何在通用 Windows 应用程序中使用非默认构造函数

c# - 彩色启动画面 - UWP 应用程序

C++ 智能卡通信

windows - NavigationView中的UWP ListView,仅呈现第一个子级

c# - 是否可以在 ASP.NET Core 中组合 [FromRoute] 和 [FromBody]?

c# - C# 使用的 native C++ 库的内存分配器

c# - 在 UpdatePanel 中使用 GridView

c# - UWP 网格过渡

c# - 启动时运行后台任务