relopjd.blogg.se

Embedded twitter feed on website
Embedded twitter feed on website




If the returned HTML is not empty, we replace it in the field’s value for display. Otherwise, we make a request to Twitter’s API to get it, put it in cache one we have it (it is set to expire after a specified number of milliseconds from the time it was retrieved: Twitter returns the number of milliseconds in one full year by default), and then we return it. If the HTML is found in cache for a Tweet, we return it. Methods in the class above find all Tweet URLs in the Rich Text, Single-Line Text, or Multi-Line Text field being processed - the code determines if it’s a Tweet URL based on a pattern that is supplied by a configuration setting (you will see this below in this post) extract Tweets’ Twitter identifiers (these are located at the end of the Tweet URLs) and attempt to find the Tweets’ HTML in Sitecore’s HTML cache. The JSON above drove me to build the following POCO class to represent data returned by that URL: While doing some research via Google on how to do this in Sitecore, I found this page from Twitter that discusses how you could go about accomplishing this, and discovered how to get JSON containing information about a Tweet - including its HTML - using one of Twitter’s API URLs: This is what is seen on the rendered page:

embedded twitter feed on website

You might be asking “what’s an Embedded Tweet?” An Embedded Tweet is basically the process of pasting a Tweet URL from Twitter into an editable content area of your website/blog/whatever (think Rich Text field in Sitecore), and let the code that builds the HTML for your site figure out how to display it.įor example, I had used an Embedded Tweet in a recent post:

embedded twitter feed on website

In a previous post, I showcased a “proof of concept” for shortcodes in Sitecore - this is a shorthand notation for embedding things like YouTube videos in your webpages without having to type up a bunch of HTML - and felt I should follow up with another “proof of concept” around incorporating Embedded Tweets in Sitecore.






Embedded twitter feed on website