Aug 14 2017 01:04 AM
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
Aug 14 2017 05:54 AM
SolutionAug 14 2017 05:56 AM
Thank you @Juan Carlos González Martín, that helped a lot!
Sep 01 2017 05:23 AM
Sep 01 2017 05:32 AM
@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; }) }