【问题标题】:How to get user id using OneDrive service in uwp community toolkit如何在 uwp 社区工具包中使用 OneDrive 服务获取用户 ID
【发布时间】:2017-12-19 16:21:16
【问题描述】:

我在 uwp 社区工具包中使用 OneDrive 服务。 我可以获取所有文件夹,但不知道如何获取用户 ID(当然不是电子邮件地址,我的意思是代表用户的唯一 ID)。

谁能帮忙,谢谢。

if (await OneDriveService.Instance.LoginAsync())
{
    _appFolder = await OneDriveService.Instance.AppRootFolderAsync();
    ShowBusy(false);
}

【问题讨论】:

    标签: c# uwp onedrive windows-community-toolkit


    【解决方案1】:

    debug的时候发现一个user id,位于OneDriveService.Instance ---- Provider ---- AuthenticationProvider ---- CurrentAccountSession ---- UserId ,但是不知道怎么获取

    如果你查看社区工具包源代码,你会发现CurrentAccountSession 属于MsaAuthenticationProvider 类。这个类位于Microsoft.OneDrive.Sdk.Authentication 命名空间中。如果您想获得UserId,则需要更改社区工具包的源代码并自行编译自定义版本。

    例如,在OneDriveService.cs 中,您可以像这样(_accountProvider as MsaAuthenticationProvider).CurrentAccountSession.UserId_accountProvider 转换为MsaAuthenticationProvider

    【讨论】:

      【解决方案2】:

      没有办法获取用户标识符。你可以实现它,然后为它提出 PR,或者你可以提出一个问题,看看情况如何。

      https://github.com/Microsoft/UWPCommunityToolkit/issues

      【讨论】:

      • 调试的时候找到一个用户id,位于OneDriveService.Instance ---- Provider ---- AuthenticationProvider ---- CurrentAccountSession ---- UserId ,但是不知道怎么弄得到它
      • @Vincent 如果查看社区工具包源代码,您会发现CurrentAccountSession 属于MsaAuthenticationProvider 类。这个类位于Microsoft.OneDrive.Sdk.Authentication 命名空间中。如果您想获得UserId,则需要更改社区工具包的源代码并自行编译自定义版本。
      • 例如,在OneDriveService.cs 中,您可以像这样将_accountProvider 转换为MsaAuthenticationProvider (_accountProvider as MsaAuthenticationProvider).CurrentAccountSession.UserId
      • @XavierXie-MSFT 我在我的代码中使用,它有效。谢谢。 string userId = (OneDriveService.Instance.Provider.AuthenticationProvider as MsaAuthenticationProvide).CurrentAccountSession.UserId;
      猜你喜欢
      • 1970-01-01
      • 2019-03-17
      • 2020-03-20
      • 1970-01-01
      • 2018-02-25
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多