2016-11-09 19 views
1

我將Onedrive SDK與Xamarin應用程序的UWP部分集成在一起。當我按下下載按鈕,我得到的Onedrive登錄頁面,但它拋出上述錯誤在這行:我得到invalidRequest拋出的異常:mscorlib.ni.dll中的'Microsoft.Graph.ServiceException'

 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; 


    } 
} 
+0

我正在從事這個 –

+0

任何更新?你有沒有檢查我的答案? –

回答

0

感謝您報告此問題。事實上,我們可以在UWP應用程序中使用OneDrive .NET SDK 2.0.4發現相關問題。我將通過內部方式報告此問題。

作爲一種變通方法,請參閱本博客:Windows 10 - Implementing a UWP App with the Official OneDrive SDK

洛朗比尼翁描述的詳細步驟(也是一個demo),以使在UWP應用OneDrive功能。

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這是現在仍在工作。