Getting your Drupal-8 website to tweet!

We often want to tweet something when adding new content to our website. The Drupal Social Initiative provides a unified framework for posting of content to various so-called social networks, but a lot is still missing. For Twitter, there is the Social Post Twitter module, which provides a service you can use to tweet, but doesn't actually deal with getting your site to tweet. But it does the hard lifting of communicating with Twitter.

Confronted with the need that we had several clients who wanted to be able to tweet from their website, we thought what would be the best approach. We decided to try to come up with some clever way of automatically generating the tweet and hashtags was not a good idea - it will always "show" in the tweet. On the other hand, you might want to tweet the same post several times, but not with exactly the same text. So we went a different route, and the module Social Post Twitter Tweet was born. This module allows you to schedule or program as many tweets as you want for each node of a content type that has the relevant field added.

Social Post Twitter Tweet: what does it do?

The module allows you to add a paragraph to any content type, and then adds some logic around that paragraph. The paragraph can be added an unlimited number of times, so you can schedule as many tweets as you want (requires a functioning cron).

The module provides a new permission "Tweet as system user", and any user with that permission can tweet using the Twitter account(s) assigned to the uid1 user, which is considered the system user (the Social Post Twitter module links all Twitter accounts to user accounts - there is no system account). This means if you have an editor role for users allowed to edit content on your website, you might want to add the permission "Tweet as system user" to this role, which will then allow them to also pick from system Twitter accounts.

A user creating or editing a node gets to select from all of the Twitter accounts available to them, which might include the system accounts. It is then possible to pre-schedule a tweet, and add a text for the tweet. The URL of the node will be appended to the tweet text automatically when the tweet is sent. This allows you to pre-schedule an unlimited number of tweets when creating or editing a node, each with a different text. This also works for multilingual content.

Present limitations

Right now, the most important limitations are:

  • we do not (yet) validate the tweet text before attempting to tweet. That means that an invalid tweet - most likely too long - will silently fail. To validate a tweet at the time of composing, we would probably need to make use of, for example,
  • You can't add images to the tweets (I am not sure Social Post Twitter can do that).

Development of this module was kindly sponsored by NATO Watch.