SOLVED

News article page comments

Iron Contributor

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

 

 

7 Replies
best response confirmed by Maggan Wåhlin (Iron Contributor)
Solution
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

Thank you @Juan Carlos González Martín, that helped a lot!

Glad to help!
Hi!

How did you get the ViewCount?

Regards,
Magnus

@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;
    }) 
  }

Hi!

Thanks! That worked!

//Magnus
Glad to help :)
1 best response

Accepted Solutions
best response confirmed by Maggan Wåhlin (Iron Contributor)
Solution
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

View solution in original post