The default Twitter web part it great and easy to use. You can follow a Twitter user (@), a URL of a user account, tweet or collection. These options where not enough for a communications department who wanted to show the #, @Company, the company name and from:[Company] on a SharePoint page. We were able to do this with a PowerAutomate Flow and a custom content query web part. In this post I will explain how you can do this.
SharePoint: Create a list
- Create a SharePoint list to store the twitter information.
- We created the following columns to store the information, your requirements might be different.
Column name | Type |
Favorite counts | Number |
Followers counts | Number |
Location | Single line of text |
Media urls | Multiple lines of text |
Original tweet | Multiple lines of text |
Original tweet tweeted by | Single line of text |
Tweet | Multiple lines of text |
Tweeted by | Single line of text |
Created at | Date and time |
TweetId | Single line of text |
Original tweet id | Single line of text |
Type | Choice |
Retweets | Single line of text |
ProfileImageUrl | Number |
NameUser | Single line of text |
Flow: Getting the information
- Open PowerAutomate and create a new Flow.
- Add the trigger When a new tweet appears.
- Enter the required search term, see the example below.
- We wanted to be able to filter on the different types of results, for example on # or @. This information is added to the item that will be created in the SharePoint list.
- A tweet can be multiple types so we need an array and append all the types to it.
- Initialize a variable called TypeTweet as an array.
- Add a scope called Append to array – TypeTweet.
- Add a condition that filters the #Office365 out of the TweetText.
- If the result is yes then append the value #Office365 to the array.
- Repeat the steps for all types of tweets.
- Add a scope called Create list item.
- Add the SharePoint Create item action.
- Connect all the columns to the correct information.
Custom Content Query Web part
We used a variation of the React Content Query Web Part from Github. This is a modern version of the CQWP where you have all the freedom to grab and style items from a list or library.
- Add the Content Query Web Part to your SharePoint page.
- Connect the CQWP to the list.
- Create the required styling with the Handlebars templating engine.