如何解决更新 OneNote 页面上的数据错误,“此流不支持超时”
我的目标是能够使用 C# 以编程方式更新 OneNote 页面数据。 Microsoft Graph API reference documentation 表明这只能由页面元素完成,不能由页面完成,并提供以下 C# Graph SDK 示例:
SELECT module.ID,count(element.ID) AS numElements FROM element JOIN module ON element.moduleID = module.ID WHERE moduleID = module.ID GROUP BY module.ID
以下是我的代码的相关片段:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(@"[
{
'target':'#para-id','action':'insert','position':'before','content':'<img src=""image-url-or-part-name"" alt=""image-alt-text"" />'
},{
'target':'#list-id','action':'append','content':'<li>new-page-content</li>'
}
]
"));
var pages = new OnenotePage();
pages.Content = stream;
await graphClient.Me.Onenote.Pages["{onenotePage-id}"]
.Request()
.UpdateAsync(pages);
Microsoft 的 REST 文档包括 GraphServiceClient client; // authenticated service client
CancellationToken cancellationToken; // a cancellation token
string userId; // identifier of user whose page contains the paragraph to be updated
string pageId; // identifier of page containing paragraph to be updated
string paragraphId; // identifier of paragraph to be updated
string filePath; // location of text file containing updated paragraph data
await client.Users[userId].Onenote.Pages[pageId]
.Request()
.UpdateAsync(new OnenotePage
{
Content = new MemoryStream(Encoding.UTF8.GetBytes(
// [
// {
// 'target':'{paragraphId}',// 'action':'replace',// 'content':'<p>{File.ReadAllText(filePath)}</p>'
// }
// ]
$"[{{'target':'{paragraphId}','action':'replace','content':'<p>{File.ReadAllText(filePath)}</p>'}}]"))
},cancellationToken);
作为有效的 HTTP 请求,所以我上面的代码似乎应该可以工作,即使它不像他们的示例那样使用 PATCH /users/{id | userPrincipalName}/onenote/pages/{id}/content
选项。但是,出于某种原因,我的代码在尝试执行 .Me
命令时不断抛出 InvalidOperationException
,声明为 "Timeouts are not supported on this stream,"
。以下是异常的详细信息:
await
当我尝试运行原始 REST 命令 on the official Graph Explorer 时,我收到一条 system.invalidOperationException
HResult=0x80131509
Message=Timeouts are not supported on this stream.
Source=System.Private.CoreLib
StackTrace:
at System.IO.Stream.get_ReadTimeout()
消息,确认 PATCH 工作正常。但请再次注意,我只是using the C# MS Graph SDK。
我哪里出错了?我怎样才能实现我的目标?
编辑:我仍然没有解决 SDK 向我抛出 No Content - 204
的解决方案,因此不认为这个问题已经解决,但由于 API 似乎正在运行很好,我继续前进并找到了一种解决方法来实现我的目标。发布在这里,以防其他人遇到我同样的问题并需要一些有用的东西。
InvalidOperationException
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。