首页 > 解决方案 > 从图形 api 创建一个 SPO 经典新闻页面

问题描述

我正在尝试从图形 api 创建一个新闻页面(首先使用资源管理器,然后以编程方式),但我遇到了一些问题。

首先,我的新闻页面包含在此 url 的“页面”列表中:/sites/myedition-edition/en-us/news/Pages/Forms/AllItems.aspx 但在尝试访问https://graph.microsoft.com/时beta/sites/[mysite-id]/pages,我收到一个未找到项目的回复。

所以我尝试将页面作为列表项上传,并遵循文档: POST https://graph.microsoft.com/beta/sites/[mysite-id]/lists/[mylist-id]/items,但后来我收到错误消息“文件和文件夹只能通过 OneDrive API 添加到 DocumentLibrary”

所以最后我尝试在相关驱动器中上传文件: https ://graph.microsoft.com/beta/sites/[mysite-id]/drives/[mydrive-id]/root:/Test1.aspx:/content 具有以下 json 正文:

{
"name": "Test1.aspx",
"title": "Test1",
"contentType": { //custom content type
    "id": "some id",
},
"fields": {
    "Title": "Test",
    "Comments": "Reference",
    "ArticleStartDate": "02-05-2021 22:00",
    "NewsURL": "https://myurl.aspx",
    "PublishingStartDate": "02-05-2021 22:00",
    "ModifiedEditable": "04-05-2021 17:37",
    "ArticleByLine": "Lorem Ipsum",
    "PublishingPageImage": "https://myurl.aspx",
}
}

然后我可以看到我的库中的文件未发布,没有设置任何属性,json 直接作为文件中的内容。要使用的正确 json 结构是什么?如何将 t 与正确的自定义内容类型相关联?上传后可以直接发布文件吗?我缺少任何步骤吗?谢谢

标签: microsoft-graph-apisharepoint-online

解决方案


推荐阅读