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 like Author, ImageURL, ViewCount and so on. Where are the comments stored, and is there a way to get the number of comments made on a news article?
Regards,
Margareta
- The 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
7 Replies
Sort By
- Magnus ForsmarkCopper ContributorHi!
How did you get the ViewCount?
Regards,
Magnus- Maggan WåhlinIron 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 ForsmarkCopper ContributorHi!
Thanks! That worked!
//Magnus
- The 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
- Maggan WåhlinIron Contributor
Thank you jcgonzalezmartin, that helped a lot!
- Glad to help!