使用Flurl从SharePoint下载文件会导致“配置系统初始化失败”错误

问题描述 投票:0回答:1

我正在使用Flurl从SharePoint下载文件。但是,它会导致“配置系统初始化失败”错误。

这是我的代码:

 var url = "https://mysite.sharepoint.com"
                .AppendPathSegment("/_api/web/Shared%20Documents/test.xlsx")
                .SetQueryParams(new
                {
                    api_key = ConfigurationManager.AppSettings["MYAPIKEY"],
                    max_results = 20,
                    q = "Don't worry, I'll get encoded!"
                })
                .SetFragment("after-hash");

                //returns fullpath for App-specific storage, where inventory data is stored
                string fullpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

                var path = await "https://mysite.sharepoint.com/Shared%20Documents/test.xlsx"
                    .DownloadFileAsync(fullpath);

我添加的API密钥是在Azure AD上生成的。

我怀疑该错误是由我的app.config文件引起的,但是由于我使用的是Xamarin.Forms,因此我最初没有app.config文件。为了解决这个问题,我使用PCLAppConfig库,并按照链接中的描述进行操作。

我的问题是,我不确定应在app.config文件中放什么。配置文件的当前内容如下,我尝试了一些不同的操作,但始终遇到相同的错误。

<configuration>
  <appSettings>
    <add key="api_key" value="MYAPIKEY" />
  </appSettings>
</configuration>

这是调用堆栈,以备不时之需:

>   0x3F in GraphTutorial.DownloadFile.Flurlcall at D:\Schule\Diplomarbeit\GraphTutorial\CalendarPage.xaml.cs:35,17 C#
    0x33 in System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<GraphTutorial.DownloadFile.<Flurlcall>d__1>    C#
    0x38 in GraphTutorial.DownloadFile.Flurlcall    C#
    0x11 in Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked at D:\a\1\s\Xamarin.Forms.Core\Button.cs:177,47  C#
    0x20 in Xamarin.Forms.ButtonElement.ElementClicked at D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:61,5 C#
    0x2 in Xamarin.Forms.Button.SendClicked at D:\a\1\s\Xamarin.Forms.Core\Button.cs:163,32 C#
    0x4 in Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick at D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25,4  C#
    0xD in Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick at D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:71,45 C#
    0x13 in Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_    C#
    0x17 in Android.Runtime.DynamicMethodNameCounter.48 C#
xamarin.forms app-config flurl
1个回答
0
投票

结果是错误与Flurl本身无关,我使用的网址是实际的问题。

我设法通过使用此查询调用Microsoft Graph API使其起作用:

GET https://graph.microsoft.com/v1.0/sites/root/drive/root:/Subfolder/test.xlsx

在响应中,您将获得属性@microsoft.graph.downloadUrl,该属性可让您下载URL。

这里的链接对我的理解大有帮助:https://docs.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http

© www.soinside.com 2019 - 2024. All rights reserved.