我正在使用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:SchuleDiplomarbeitGraphTutorialCalendarPage.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:a1sXamarin.Forms.CoreButton.cs:177,47 C#
0x20 in Xamarin.Forms.ButtonElement.ElementClicked at D:a1sXamarin.Forms.CoreButtonElement.cs:61,5 C#
0x2 in Xamarin.Forms.Button.SendClicked at D:a1sXamarin.Forms.CoreButton.cs:163,32 C#
0x4 in Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick at D:a1sXamarin.Forms.Platform.AndroidButtonElementManager.cs:25,4 C#
0xD in Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick at D:a1sXamarin.Forms.Platform.AndroidFastRenderersButtonRenderer.cs:71,45 C#
0x13 in Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ C#
0x17 in Android.Runtime.DynamicMethodNameCounter.48 C#
事实证明,该错误与 Flurl 本身无关,我使用的网址是实际问题。
我设法通过使用此查询调用 Microsoft 图形 API 来使其工作:
GET https://graph.microsoft.com/v1.0/sites/root/drive/root:/Subfolder/test.xlsx
在响应中,您将获得属性@microsoft.graph.downloadUrl
,该属性允许您下载 url。
这是一个链接,对我解决这个问题有很大帮助: https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http