Microsoft graph api 更新OneNote页面上的数据时出现错误,";此流上不支持超时”;

Microsoft graph api 更新OneNote页面上的数据时出现错误,";此流上不支持超时”;,microsoft-graph-api,microsoft-graph-sdks,microsoft-graph-onenote,Microsoft Graph Api,Microsoft Graph Sdks,Microsoft Graph Onenote,我的目标是能够使用C#以编程方式更新OneNote页面数据。建议这只能通过page元素而不是page来完成,并给出了以下C#Graph SDK示例: GraphServiceClient graphClient = new GraphServiceClient( authProvider ); var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(@"[ { 'target':'#para-id',

我的目标是能够使用C#以编程方式更新OneNote页面数据。建议这只能通过page元素而不是page来完成,并给出了以下C#Graph SDK示例:

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);
当我尝试运行raw REST命令时,会收到一条
No Content-204
消息,确认修补程序工作正常。然而,请再次注意,我只是简单的

我哪里做错了?我怎样才能实现我的目标

<强>编辑:我仍然没有解决SDK投掷<代码>无效操作异常> /Case>S的方法,因此不考虑解决这个问题,但是由于API看起来工作正常,所以我开始着手解决问题。张贴在这里,以防其他人遇到我同样的问题,并需要一些工作

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

HttpRequestMessage request = new HttpRequestMessage(
    HttpMethod.Patch,
    client.Users[userId].Onenote.Pages[pageId].Content
        .Request()
        .RequestUrl)
{
    Content = new StringContent(
        // [
        //    {
        //       'target':'{paragraphId}',
        //       'action':'replace',
        //       'content':'<p>{File.ReadAllText(filePath)}</p>'
        //    }
        // ]
        $"[{{'target':'{paragraphId}','action':'replace','content':'<p>{File.ReadAllText(filePath)}</p>'}}]",
        Encoding.UTF8,
        "application/json")
};

await client.AuthenticationProvider.AuthenticateRequestAsync(request);
await client.HttpProvider.SendAsync(request);
GraphServiceClient客户端;//认证服务客户端
CancellationToken CancellationToken;//取消代币
字符串userId;//其页面包含要更新段落的用户的标识符
字符串pageId;//包含要更新段落的页面标识符
字符串段落ID;//待更新段落的标识符
字符串文件路径;//包含更新段落数据的文本文件的位置
HttpRequestMessage请求=新建HttpRequestMessage(
HttpMethod.Patch,
client.Users[userId].Onenote.Pages[pageId].Content
.Request()
.RequestUrl)
{
内容=新内容(
// [
//    {
//'目标':'{paragraphId}',
//“操作”:“替换”,
//“内容”:“{File.ReadAllText(filePath)}

” // } // ] $“[{'target':'{paragraphId}','action':'replace','content':'{File.ReadAllText(filePath)}

'}], Encoding.UTF8, “应用程序/json”) }; 等待client.AuthenticationProvider.AuthenticateRequestAsync(请求); 等待client.HttpProvider.SendAsync(请求);
(1)与requestid、timestamp(2)共享详细的错误代码。在上述代码之外,您是否可以使用相同的负载与Graph Explorer/POSTMAN重新编写相同的错误代码?我已经更新了我的帖子,以尽可能多地包含请求的信息。好的,下面是我的收获。如果是图形错误,那么您将收到图形错误代码以及requestid,以及它的时间戳。不幸的是,您指出的上述错误与Windows错误代码有关(请查看十六进制代码值);这就是为什么当您尝试使用Graph explorer时,补丁调用成功了。很高兴我们将这个问题从图形中分离出来,所以现在您可以集中讨论为什么从API调用中收到Windows错误。@Dev此错误是由生成的。所以这不仅仅是一个windows错误。谢谢@BrentArias,那么问题在于Graph SDK,而不是API。很高兴看到你把这个问题提交到了报告中。让我们等待更新,因为。。。
System.InvalidOperationException
    HResult=0x80131509
    Message=Timeouts are not supported on this stream.
    Source=System.Private.CoreLib
    StackTrace:
     at System.IO.Stream.get_ReadTimeout()
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

HttpRequestMessage request = new HttpRequestMessage(
    HttpMethod.Patch,
    client.Users[userId].Onenote.Pages[pageId].Content
        .Request()
        .RequestUrl)
{
    Content = new StringContent(
        // [
        //    {
        //       'target':'{paragraphId}',
        //       'action':'replace',
        //       'content':'<p>{File.ReadAllText(filePath)}</p>'
        //    }
        // ]
        $"[{{'target':'{paragraphId}','action':'replace','content':'<p>{File.ReadAllText(filePath)}</p>'}}]",
        Encoding.UTF8,
        "application/json")
};

await client.AuthenticationProvider.AuthenticateRequestAsync(request);
await client.HttpProvider.SendAsync(request);