微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更新 OneNote 页面上的数据错误,“此流不支持超时”

如何解决更新 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?