CAM 查询请求中缺少 _LikeCount 和 _CommentCount 字段
_LikeCount and _CommentCount field is missing on CAM Query Request
您好,我正在创建 spfx webpart 来显示最喜欢和评论最多的新闻,但是 _LikeCount 和 _CommentCount 没有出现在结果中。
见下面的代码:
props.topCount = props.topCount === undefined ? 5: props.topCount;
console.log("Count: " + props.topCount);
const options: ISPHttpClientOptions = {
headers: {'odata-version':'3.0'},
body: `{'query': {
'__metadata': {'type': 'SP.CamlQuery'},
'ViewXml': '<View><Query><OrderBy><FieldRef Name="_CommentCount" Ascending="False" /></OrderBy><Where><Eq><FieldRef Name="PromotedState" /><Value Type="Number">2</Value></Eq></Where></Query><RowLimit>`+props.topCount+`</RowLimit></View>'
}}`
};
const fetchData = async () => {
let currentWebUrl = props.sites === undefined ? props.origSiteURL : props.sites[0].url;
console.log("Site URL: " + currentWebUrl);
let requestUrl = currentWebUrl.concat("/_api/web/lists/GetByTitle('Site Pages')/GetItems");
console.log("Current URL: "+ requestUrl);
props.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, options)
.then((response: SPHttpClientResponse) => {
if (response.ok) {
response.json().then((responseJSON) => {
if (responseJSON!=null && responseJSON.value!=null){
settop_news_like(responseJSON.value);
console.log(settop_news_like);
}
});
}
});
};
还尝试添加:
<ViewFields>
<FieldRef Name="_LikeCount"></FieldRef>
<FieldRef Name="_CommentCount"></FieldRef>
</ViewFields>
和下面这个,但仍然没有运气。
expand=fields($select=createdDateTime,BannerImageUrl,PromotedState,FileLeafRef,AuthorLookupId,Modified,_CommentCount,_LikeCount,Title,Description,LinkTitle)
有一个单独的 API 用于获取现代页面的点赞和评论计数。下面的文章解释了如何使用 RenderListDataAsStream
api:
获取页面的这些字段
https://www.eliostruyf.com/getting-likes-and-comments-from-modern-pages/
您好,我正在创建 spfx webpart 来显示最喜欢和评论最多的新闻,但是 _LikeCount 和 _CommentCount 没有出现在结果中。
见下面的代码:
props.topCount = props.topCount === undefined ? 5: props.topCount;
console.log("Count: " + props.topCount);
const options: ISPHttpClientOptions = {
headers: {'odata-version':'3.0'},
body: `{'query': {
'__metadata': {'type': 'SP.CamlQuery'},
'ViewXml': '<View><Query><OrderBy><FieldRef Name="_CommentCount" Ascending="False" /></OrderBy><Where><Eq><FieldRef Name="PromotedState" /><Value Type="Number">2</Value></Eq></Where></Query><RowLimit>`+props.topCount+`</RowLimit></View>'
}}`
};
const fetchData = async () => {
let currentWebUrl = props.sites === undefined ? props.origSiteURL : props.sites[0].url;
console.log("Site URL: " + currentWebUrl);
let requestUrl = currentWebUrl.concat("/_api/web/lists/GetByTitle('Site Pages')/GetItems");
console.log("Current URL: "+ requestUrl);
props.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, options)
.then((response: SPHttpClientResponse) => {
if (response.ok) {
response.json().then((responseJSON) => {
if (responseJSON!=null && responseJSON.value!=null){
settop_news_like(responseJSON.value);
console.log(settop_news_like);
}
});
}
});
};
还尝试添加:
<ViewFields>
<FieldRef Name="_LikeCount"></FieldRef>
<FieldRef Name="_CommentCount"></FieldRef>
</ViewFields>
和下面这个,但仍然没有运气。
expand=fields($select=createdDateTime,BannerImageUrl,PromotedState,FileLeafRef,AuthorLookupId,Modified,_CommentCount,_LikeCount,Title,Description,LinkTitle)
有一个单独的 API 用于获取现代页面的点赞和评论计数。下面的文章解释了如何使用 RenderListDataAsStream
api:
https://www.eliostruyf.com/getting-likes-and-comments-from-modern-pages/