Forum Discussion
Maggan Wåhlin
Aug 14, 2017Iron Contributor
News article page comments
Hi! I am currently working on a project using the SharePoint Framework. I'm looking for a way to get the comments made by users on a page. The pages are news articles, and I am able to get info l...
- Aug 14, 2017The comments are not stored in SPO itself...take a look at this: http://www.vrdmn.com/2017/07/working-with-page-comments-rest-api-in.html
Magnus Forsmark
Sep 01, 2017Copper Contributor
Hi!
How did you get the ViewCount?
Regards,
Magnus
How did you get the ViewCount?
Regards,
Magnus
Maggan Wåhlin
Sep 01, 2017Iron Contributor
Magnus Forsmark, I got it from the JSON response object. I am somewhat a beginner at SPFx, so I am not 100% sure this is the correct approach, but here´s an example:
private getNews(url: string) : Promise<any> { return this.context.spHttpClient.get(url, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => { if (response.ok) { return response.json(); } else { console.log("WARNING - failed to hit URL " + url + ". Error = " + response.statusText); return null; } }); } private getNewsItems(): Promise<NewsItem[]> { // URL to get news var url = this.context.pageContext.web.absoluteUrl + `/_vti_bin/homeapi.ashx/news?start=0&count=200`; return this.getNews(url).then((response) => { var news: Array<NewsItem> = new Array<NewsItem>(); response.Items.forEach((item: any) => { var newsItem = new NewsItem(); newsItem.Title = item.Title; newsItem.Published = item.FirstPublishedDate; newsItem.Author = item.Author.Title; newsItem.URL = item.Url; newsItem.Text = item.Description; newsItem.ImageUrl = item.ImageUrl; newsItem.LastModifiedBy = item.LastModifiedBy; newsItem.ViewCount = item.ViewCount == null ? 0 : item.ViewCount; news.push(newsItem); }); return news; }) }
- Magnus ForsmarkSep 01, 2017Copper ContributorHi!
Thanks! That worked!
//Magnus- Maggan WåhlinSep 01, 2017Iron ContributorGlad to help :-)