This project is part of the Drupal Social Initiative.

Social Post Twitter allows you to configure your site to automatically tweet to a users' accounts without human intervention. It is based on Social Post and Social API projects

Examples of use cases

  • Update status when a new content has been added.
  • Share a video link (stored in a field) after flagging some content.
  • Let user's announce on their Twitter profile they have just bought a product (and link to it).
  • Welcome new Drupal users on your site's Twitter account.

The module allows you to:

  • Grant access to write to your (or admin’s ones) Twitter account.
  • Associate as many account as you like.
  • Personalize the status text to be tweeted.

How to use?

You can use the token obtained from Twitter to tweet on behalf of the user. Each user has to authorize the Twitter app on the user edit form. If you want to set up a general site account, you can create a Drupal user account and authenticate your site's Twitter account. Later, you can use the uid of this user to tweet on behalf of your site using the API.

API based usage

Example:

// Create and post manager instances.
/** @var Abraham\TwitterOAuth\TwitterOAuth $client */
$client = \Drupal::service('plugin.network.manager')->createInstance('social_post_twitter')->getSdk();
/** @var Drupal\social_post_twitter\TwitterPostManager $post_manager */
$post_manager = \Drupal::service('twitter_post.manager');

// Get accounts for the current user.
/* @var Drupal\social_post\Entity\SocialPost[] $accounts */
$accounts = \Drupal::service('social_post.user_manager')->getAccounts('social_post_twitter');

foreach ($accounts as $account) {
  // Set OAuth token for the account.
  $token = json_decode($account->getToken());
  $client->setOauthToken($token->oauth_token, $token->oauth_token_secret);

  // Make a post to Twitter with the account!
  $post_manager->setClient($client)->doPost('New post via Social Post Twitter!');
}

Rules based usage

First install this module and associate a Drupal user with a Twitter account.

  1. Install and enable the Rules module.
  2. Navigate to Configuration > Rules (/admin/config/workflow/rules) and click "Add reaction rule".
  3. Select a React on event value (e.g. "After saving a new content node").
  4. Set a Label for the rule (e.g. "New content node tweet").
  5. Click "Save".
  6. On the rule edit page, click "Add action".
  7. Select the "Tweet" action under the "Social Post" option group in the Action field.
  8. Click "Continue".
  9. Input the text to be tweeted -- e.g. A new article "{{ node.title.value }}" has been published on my website at {{ node | entity_url }}
  10. Click "Save".
  11. Add other conditions and/or actions as desired.
  12. Click "Save".

The rule is now ready! Post a new node using a Drupal user that has at least one linked Twitter account and the tweet should post automatically.

Supporting organizations: 
Ongoing maintenance.
Initial planning and development.
Initial planning and development.

Project information

Releases