命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
在网站的网站页面列表中创建新的 newsLinkPage。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Sites.ReadWrite.All |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
Sites.ReadWrite.All |
不可用。 |
HTTP 请求
POST /sites/{site-id}/pages
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Type |
json 内容的 application/json,包括多部分请求中所需的 标题 属性。 多部分请求使用多部分/表单数据;boundary=your-boundary 内容类型。 必填。 |
Prefer |
include-unknown-enum-members。 使用 Prefer: include-unknown-enum-members 请求标头在 pageLayoutType 中获取以下值,这是 一个可演变枚举: newsLink 。 |
请求正文
在请求正文中,提供 newsLinkPage 对象的 JSON 表示形式。 正文必须包含直接放置在请求正文中的必需属性;但是,若要通过上传图像来设置横幅图像,它必须采用多部分消息格式,如示例中所示。 对于横幅图像上传,必须发送多部分请求,因为它涉及二进制数据。
注意:
- 若要确保成功分析请求正文,
@odata.type=#microsoft.graph.newsLinkPage
必须在请求正文中包含 。
- 目前,若要设置 横幅ImageWebUrl,存在直接上传图像字节的功能。 这些字节会自动保存在网站资产库中,然后根据持久化文件生成 bannerImageWebUrl 。 为此,请发出多部分请求,
@microsoft.graph.bannerImageWebUrlContent
并设置批注以发送图像内容。 有关更多详细信息,请参阅 示例 2。
创建 newsLinkPage 时,可以指定以下属性。
属性 |
类型 |
说明 |
说明 |
String |
项目的描述性文本。 最大长度限制为 250 个字符。 可选。 继承自 baseSitePage。 |
newsWebUrl |
String |
newsLinkPage 引用的新闻文章的 URL。 它可以是外部链接。 必填。 |
title |
String |
newsLinkPage 的标题。 最大长度限制为 110 个字符。 必填。 继承自 baseSitePage。 |
响应
如果成功,此方法在响应正文中返回响应 201 Created
代码和 newsLinkPage 对象。
示例
示例 1:创建仅具有所需属性的新闻链接页面
以下示例演示如何仅使用所需属性创建 新闻链接页 。
请求
以下示例显示了一个请求。
POST /sites/c1370818-f5e0-4a40-a99b-be4520640642/pages
prefer: include-unknown-enum-members
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.newsLinkPage",
"newsWebUrl":"https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car",
"title": "Contoso Unveils First Self-Driving Car"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new NewsLinkPage
{
OdataType = "#microsoft.graph.newsLinkPage",
NewsWebUrl = "https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car",
Title = "Contoso Unveils First Self-Driving Car",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites["{site-id}"].Pages.PostAsync(requestBody, (requestConfiguration) =>
{
requestConfiguration.Headers.Add("prefer", "include-unknown-enum-members");
});
mgc-beta sites pages create --site-id {site-id} --body '{\
"@odata.type": "#microsoft.graph.newsLinkPage",\
"newsWebUrl":"https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car",\
"title": "Contoso Unveils First Self-Driving Car"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
abstractions "github.com/microsoft/kiota-abstractions-go"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
graphsites "github.com/microsoftgraph/msgraph-beta-sdk-go/sites"
//other-imports
)
headers := abstractions.NewRequestHeaders()
headers.Add("prefer", "include-unknown-enum-members")
configuration := &graphsites.ItemPagesRequestBuilderPostRequestConfiguration{
Headers: headers,
}
requestBody := graphmodels.NewBaseSitePage()
newsWebUrl := "https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car"
requestBody.SetNewsWebUrl(&newsWebUrl)
title := "Contoso Unveils First Self-Driving Car"
requestBody.SetTitle(&title)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
pages, err := graphClient.Sites().BySiteId("site-id").Pages().Post(context.Background(), requestBody, configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
NewsLinkPage baseSitePage = new NewsLinkPage();
baseSitePage.setOdataType("#microsoft.graph.newsLinkPage");
baseSitePage.setNewsWebUrl("https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car");
baseSitePage.setTitle("Contoso Unveils First Self-Driving Car");
BaseSitePage result = graphClient.sites().bySiteId("{site-id}").pages().post(baseSitePage, requestConfiguration -> {
requestConfiguration.headers.add("prefer", "include-unknown-enum-members");
});
const options = {
authProvider,
};
const client = Client.init(options);
const baseSitePage = {
'@odata.type': '#microsoft.graph.newsLinkPage',
newsWebUrl: 'https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car',
title: 'Contoso Unveils First Self-Driving Car'
};
await client.api('/sites/c1370818-f5e0-4a40-a99b-be4520640642/pages')
.version('beta')
.post(baseSitePage);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Sites\Item\Pages\PagesRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Beta\Generated\Models\NewsLinkPage;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new NewsLinkPage();
$requestBody->setOdataType('#microsoft.graph.newsLinkPage');
$requestBody->setNewsWebUrl('https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car');
$requestBody->setTitle('Contoso Unveils First Self-Driving Car');
$requestConfiguration = new PagesRequestBuilderPostRequestConfiguration();
$headers = [
'prefer' => 'include-unknown-enum-members',
];
$requestConfiguration->headers = $headers;
$result = $graphServiceClient->sites()->bySiteId('site-id')->pages()->post($requestBody, $requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Sites
$params = @{
"@odata.type" = "#microsoft.graph.newsLinkPage"
newsWebUrl = "https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car"
title = "Contoso Unveils First Self-Driving Car"
}
New-MgBetaSitePage -SiteId $siteId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.sites.item.pages.pages_request_builder import PagesRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph_beta.generated.models.news_link_page import NewsLinkPage
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = NewsLinkPage(
odata_type = "#microsoft.graph.newsLinkPage",
news_web_url = "https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car",
title = "Contoso Unveils First Self-Driving Car",
)
request_configuration = RequestConfiguration()
request_configuration.headers.add("prefer", "include-unknown-enum-members")
result = await graph_client.sites.by_site_id('site-id').pages.post(request_body, request_configuration = request_configuration)
响应
以下示例显示了相应的响应。
HTTP/1.1 201 Created
Content-type: application/json
{
"eTag": "\"{6A34958A-6F84-4571-A26E-B2CEB20261EB},3\"",
"id": "6a34958a-6f84-4571-a26e-b2ceb20261eb",
"lastModifiedDateTime": "2023-09-10T18:46:23Z",
"name": "contoso-unveils-first-self-driving-car.aspx",
"webUrl": "https://contoso.sharepoint.com/SitePages/contoso-unveils-first-self-driving-car.aspx",
"title": "Contoso Unveils First Self-Driving Car",
"pageLayout": "newsLink",
"newsWebUrl": "https://someexternalnewssite.com/2024/11/11/contoso-unveils-first-self-driving-car",
"createdBy": {
"user": {
"displayName": "Jane Doe"
}
},
"lastModifiedBy": {
"user": {
"displayName": "Jane Doe"
}
},
"contentType": {
"id": "0x0101009D1CB255DA76424F860D91F20E6C4118002A50BFCFB7614729B56886FADA02339B000B27C676C81DC54289A1417148759BF3",
"name": "Repost Page"
},
"publishingState": {
"level":"checkout",
"versionId":"0.1",
"checkedOutBy": {
"user": {
"displayName":"Jane Doe",
"email":"JaneDoe@contoso.sharepoint.com"
}
}
}
}
示例 2:创建新闻链接页面并上传横幅图像文件内容
以下示例演示如何创建带有横幅图像的 新闻链接页面 。 此过程需要多部分请求。
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/beta/sites/c1370818-f5e0-4a40-a99b-be4520640642/pages
Prefer: include-unknown-enum-members
Content-type: multipart/form-data; boundary=MyPartBoundary198374
--MyPartBoundary198374
Content-Disposition: form-data; name="request"
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.newsLinkPage",
"title": "Microsoft Build brings AI tools to the forefront for developers",
"newsWebUrl": "https://someexternalnewssite.com/2024/05/23/microsoft-build-ai-tools-developers",
"description": "You only need two simple letters to accurately convey the major shift in the technology space this year: A and I. Beyond those letters, however, is a complex, evolving and exciting way in which we work, communicate and collaborate.",
"@microsoft.graph.bannerImageWebUrlContent": "name:content"
}
--MyPartBoundary198374
Content-Disposition: form-data; name="content"; filename="b3.jpg"
Content-Type: image/jpeg
... binary image data ...
--MyPartBoundary198374
mgc-beta sites pages create --site-id {site-id}
const options = {
authProvider,
};
const client = Client.init(options);
const baseSitePage = --MyPartBoundary198374
Content-Disposition: form-data; name='request'
Content-Type: application/json
{
'@odata.type': '#microsoft.graph.newsLinkPage',
title: 'Microsoft Build brings AI tools to the forefront for developers',
newsWebUrl: 'https://someexternalnewssite.com/2024/05/23/microsoft-build-ai-tools-developers',
description: 'You only need two simple letters to accurately convey the major shift in the technology space this year: A and I. Beyond those letters, however, is a complex, evolving and exciting way in which we work, communicate and collaborate.',
'@microsoft.graph.bannerImageWebUrlContent': 'name:content'
}
--MyPartBoundary198374
Content-Disposition: form-data; name='content'; filename='b3.jpg'
Content-Type: image/jpeg
... binary image data ...
--MyPartBoundary198374;
await client.api('/sites/c1370818-f5e0-4a40-a99b-be4520640642/pages')
.version('beta')
.post(baseSitePage);
响应
以下示例显示了相应的响应。 如果在上传或保留横幅图像时失败,响应将 @microsoft.graph.bannerImageWebUrlContentError
包含和描述性错误消息。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.newsLinkPage",
"createdDateTime": "2024-06-11T17:31:20Z",
"description": "You only need two simple letters to accurately convey the major shift in the technology space this year: A and I. Beyond those letters, however, is a complex, evolving and exciting way in which we work, communicate and collaborate.",
"eTag": "\"{179210C2-637E-4C61-8491-331D0D4A0C05},2\"",
"id": "179210c2-637e-4c61-8491-331d0d4a0c05",
"lastModifiedDateTime": "2024-06-11T17:31:21Z",
"name": "microsoft-build-ai-tools-developers.aspx",
"webUrl": "https://contoso.sharepoint.com/SitePages/Microsoft-Build-brings-AI-tools-to-the-forefront-for-developers.aspx",
"title": "Microsoft Build brings AI tools to the forefront for developers",
"pageLayout": "newsLink",
"bannerImageWebUrl": "https://contoso.sharepoint.com/_layouts/15/getpreview.ashx?path=/SiteAssets/SitePages/microsoft-build-ai-tools-developers/BannerImage.png",
"newsWebUrl": "https://someexternalnewssite.com/2024/05/23/microsoft-build-ai-tools-developers",
"createdBy": {
"user": {
"displayName": "John Doe",
"email": "jdoe@contoso.com"
}
},
"lastModifiedBy": {
"user": {
"displayName": "John Doe",
"email": "jdoe@contoso.com"
}
},
"publishingState": {
"level": "checkout",
"versionId": "0.1",
"checkedOutBy": {
"user": {
"displayName": "John Doe",
"email": "jdoe@contoso.com"
}
}
}
}