The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
This post exposes a way to implement selective and instant Twitter publishing for items upon their creation. The approach relies on Sitefinity's EventHub data provider events, and a third party API - Tweetinvi.
First off a big thank you goes to the guys from Tweetinvi for providing a C# API we can take advantage of. In order to have access to their API you will need to download their assemblies and add them to your application (see link above).
Once done you'll have access to their methods, and you are good to go. Next up is to get Sitefinity to play nice with them. The scenario I am going to cover is to publish a dynamic content type (Sample Content) item and decide whether to tweet the content of the item based on the value of a Yes/No field.
In order to take advantage of Tweetinvi's methods you will first need to authenticate a Twitter application. Once done you are authenticated on a thread scope, so there is no need to do so with every tweet. You can use the Default Sitefinity Twitter application. If you chose to use your own application, please add it in the backend and get its Access Token, Access Token Secret, Consumer Key, and Consumer Secret. They can be found in the Advanced Settings under the Twitter section. The Authentication is done in the Application_Start of the Global.asax file:
This is all there is to it. From then on your tweets will be send via the account associated with this application.
Next we need to intercept the publishing of the content items we would like to tweet. For this purpose I have used Sitefinity's EventHub. More precisely I attached to the IDynamicCreatedEvent. A simple check is made there based on the type of the item and its status. The important thing here is the value of the Yes/No field. This will determine whether to tweet the item or not:.
This is all that is needed. At this point you will tweet the content of your items based on the field value.I hope you find the above sample interesting and useful. As always your opinion is really important to us, so please feel free to let us know what you think if you have any comments/ideas.
View all posts from Ivan D.Dimitrov on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
You have the right to request deletion of your Personal Information at any time.
You can also ask us not to pass your Personal Information to third parties here: Do Not Sell My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.Learn More