更新页面
本文内容
命名空间:microsoft.graph
更新页面OneNote内容。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Notes.ReadWrite、Notes.ReadWrite.All
委派(个人 Microsoft 帐户)
Notes.ReadWrite
应用程序
Notes.ReadWrite.All
HTTP 请求
PATCH /me/onenote/pages/{id}/content
PATCH /users/{id | userPrincipalName}/onenote/pages/{id}/content
PATCH /groups/{id}/onenote/pages/{id}/content
PATCH /sites/{id}/onenote/pages/{id}/content
名称
类型
说明
Authorization
string
Bearer {token}。必需。
Content-Type
string
application/json
请求正文
在请求正文中,提供一个 patchContentCommand 对象数组,这些对象代表对页面的更改。 有关详细信息和示例,请参阅更新OneNote页面 。
响应
如果成功,此方法返回 204 No Content 响应代码。 PATCH 请求未返回任何 JSON 数据。
示例
请求
下面是一个请求示例。
PATCH https://graph.microsoft.com/v1.0/me/onenote/pages/{id}/content
Content-type: application/json
[
{
'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>'
}
]
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);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const stream = [
{
\'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>\'
}
];
await client.api('/me/onenote/pages/{id}/content')
.update(stream);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/onenote/pages/{id}/content"]]];
[urlRequest setHTTPMethod:@"PATCH"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableArray *streamList = [[NSMutableArray alloc] init];
MSGraphStream *stream = [[MSGraphStream alloc] init];
[stream setTarget:@"#para-id"];
[stream setAction:@"insert"];
[stream setPosition:@"before"];
[stream setContent:@"<img src=\"image-url-or-part-name\" alt=\"image-alt-text\" />"];
[streamList addObject: stream];
MSGraphStream *stream = [[MSGraphStream alloc] init];
[stream setTarget:@"#list-id"];
[stream setAction:@"append"];
[stream setContent:@"<li>new-page-content</li>"];
[streamList addObject: stream];
NSError *error;
NSData *streamData = [stream getSerializedDataWithError:&error];
[urlRequest setHTTPBody:streamData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Stream> streamList = new LinkedList<Stream>();
Stream stream = new Stream();
stream.target = "#para-id";
stream.action = "insert";
stream.position = "before";
stream.content = "<img src=\"image-url-or-part-name\" alt=\"image-alt-text\" />";
streamList.add(stream);
Stream stream1 = new Stream();
stream1.target = "#list-id";
stream1.action = "append";
stream1.content = "<li>new-page-content</li>";
streamList.add(stream1);
graphClient.customRequest("/me/onenote/pages/{id}/content", Stream.class)
.buildRequest()
.patch(stream);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
onenotePageId := "onenotePage-id"
graphClient.Me().Onenote().PagesById(&onenotePageId).Content().Patch()
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面是一个响应示例。
HTTP/1.1 204 No Content