更新 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.JdbcOdbc...