To set up automatic posting to Twitter when content is created, we need the Twitter and oAuth modules. They act as a communication protocol between Drupal and Twitter.
First, we need to register an application on Twitter. To do this, go to dev.twitter.com, log in, and register a new application. When filling out the form, enter the Callback URL from your Drupal site into the Callback field. By default, the Twitter module provides a callback at https://yoursite.com/twitter/oauth
, so you should replace this with your domain.
Next, configure the application to allow posting messages. Go to the Settings
tab and set the Access field to Read
and Write
.
After that, on the Details tab, click the Create my access token
button at the bottom of the form to generate access keys. Make sure the Access level is set to Read
and Write
. If everything looks correct, continue to the next step.
Now you can set up the module directly on your site. Download and install the Twitter and oAuth modules.
Modules you need to enable:
- oAuth
- Twitter Post
After enabling these modules, go to admin/config/services/twitter
. In the OAuth Consumer key
and OAuth Consumer
secret fields, enter the values provided on your Twitter application’s page. Configuration for posting messages to Twitter can be adjusted at admin/config/services/twitter/post
. Here, you can select the content types allowed to post to Twitter and edit the content of the tweet.
Finally, add the Twitter account where messages will be posted. Go to user/%/edit/twitter
and add the Twitter account to your Drupal user account. You can also manage account access settings on this page. By clicking the make global
button, you can allow other site users who have content creation permissions to post messages to this Twitter account.
If you have issues adding your account, Open SSL might be disabled on your server. To enable it in XAMPP, add the following lines to your php.ini
:
[PHP_OPENSSL]
extension=php_openssl.dll
Now create content that has Twitter posting enabled in the settings. In the content creation form, a tab will appear allowing you to enable posting and edit the tweet.
After saving the content, the message will appear on Twitter. If you encounter issues with message posting or connection problems, check the error logs. Their messages will help identify the problem.
This post describes how to set up message posting when content is created. For more detailed event-based configuration, you can use the Rules module. After enabling the Twitter actions module, an action called Post a message to Twitter will appear in Rules settings.