【问题标题】:I get invalidRequest Exception thrown: 'Microsoft.Graph.ServiceException' in mscorlib.ni.dll我在 mscorlib.ni.dll 中抛出了 invalidRequest Exception: 'Microsoft.Graph.ServiceException'
【发布时间】:2016-11-11 18:47:52
【问题描述】:

我正在将 Onedrive SDK 与我的 Xamarin 应用程序的 UWP 部分集成。一旦我按下下载按钮,我会得到 Onedrive 登录页面,但它会在此行中引发上述错误:

     try
    {
        var appFolder = await OneDriveClient.Drive.Special.AppRoot.Request().GetAsync();
        Debug.WriteLine(appFolder.Name);
    }
    catch (ServiceException e  )
    {
        Debug.WriteLine(e.Message +"    " +  e.Error.Code);

    }

这里是完整的相关代码:

     public async Task Download(string filename)
{
    //AccountSelectionLoaded();
    await InitializeClient();
    try
    {
        var appFolder = await OneDriveClient.Drive.Special.AppRoot.Request().GetAsync();
        Debug.WriteLine(appFolder.Name);
    }
    catch (ServiceException e  )
    {
        Debug.WriteLine(e.Message +"    " +  e.Error.Code);

    }

    var file = await OneDriveClient.Drive.Special.AppRoot.Children[filename].Content.Request().GetAsync();

    //var fileStream = await fileBuilder.Content.Request().GetAsync();

    IStorageFile appFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.db3",
                        CreationCollisionOption.OpenIfExists);
    byte[] fileBytes;
   using (DataReader reader = new DataReader(file.AsInputStream()))
        {
            fileBytes = new byte[file.Length];
            await reader.LoadAsync((uint)file.Length);
            reader.ReadBytes(fileBytes);
        }
   Debug.WriteLine(fileBytes.Length);
    Debug.WriteLine("Writing");
    await FileIO.WriteBytesAsync(appFile, fileBytes);
    Debug.WriteLine("End of writing");       
}

private async Task InitializeClient()
{
    if (OneDriveClient == null)
    {
        Task authTask;
        var msaAuthProvider = new MsaAuthenticationProvider(oneDriveConsumerClientId,oneDriveConsumerReturnUrl,scopes);
        await msaAuthProvider.AuthenticateUserAsync();
        OneDriveClient = new OneDriveClient(oneDriveConsumerBaseUrl, msaAuthProvider);

        AuthenticationProvider = msaAuthProvider;


    }
}

【问题讨论】:

  • 我正在处理这个
  • 有什么更新吗?你检查我的答案了吗?

标签: xamarin.forms uwp microsoft-graph-api onedrive


【解决方案1】:

感谢您报告此问题。实际上,我们可以在 UWP 应用中使用 OneDrive .NET SDK 2.0.4 看到相关问题

我会通过内部方式报告这个问题。

作为一种解决方法,请参阅此博客:Windows 10 - Implementing a UWP App with the Official OneDrive SDK

Laurent Bugnion 描述了在 UWP 应用中启用 OneDrive 功能的详细步骤(以及 demo)。

private IOneDriveClient _client;
public MainPage()
{
  InitializeComponent();
  AuthenticateButton.Click += async (s, e) =>
  {
    var scopes = new[]
    {
      "onedrive.readwrite",
      "onedrive.appfolder",
      "wl.signin"
    };
    _client = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(
      _scopes);
    var session = await client.AuthenticateAsync();
    Debug.WriteLine($"Token: {session.AccessToken}");
  };
}

当时,该项目正在使用1.2.0 SDK现在仍在工作

【讨论】:

    猜你喜欢
    • 2015-09-27
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多