Last updated 2 November 2016. Created on 19 November 2011.
Edited by sprite, pfrenssen, chrisjlee, juampynr. Log in to edit this page.

Twitter module

The Drupal Twitter module adds support to authenticate Twitter accounts to Drupal user accounts, and pull and list its tweets. Once an authenticated Twitter account has been added (which means that it is an account that belongs to you and therefore you authenticate it by being redirected to Twitter.com), other non-authenticated Twitter accounts can be added too (you do not need to authenticate them).

This module also contain three sub-modules:

  • Twitter actions: Adds actions to send Twitter messages when ever an Drupal action is run (thanks to Action and Trigger core modules). It also supports Rules.
  • Twitter post: Implements a field to Post to Twitter when content is created or edited.
  • Twitter Signin: Lets Drupal users log into Drupal through a Twitter account.

Installation

Install and enable modules

Download, install and enable the Twitter and OAuth modules.

Create a Twitter application

In order to communicate with the Twitter API, you need to create a Twitter application at https://apps.twitter.com/. Go to https://apps.twitter.com/app/new and register (create) your application (Drupal site). Replace 127.0.0.1 by your website domain if you have one. If you do not, use these suggested values for Website and Callback URL fields. Twitter requires that you add a phone number to your twitter account before they'll provide access.

twitter_create_application.png

Set up application permissions

Go to the settings tab of your application and review the following permissions:

  • If you want to Post to Twitter (using twitter_post submodule), then change the Access type to Read and write.
  • If you want to Sign in with a Twitter account (using twitter_signin submodule), enable the checkbox.

twitter_permissions.png

Copy OAuth keys to your site

Go back to the "Details" tab of your application at http://dev.twitter.com and copy the Consumer key and Consumer secret keys into the Twitter module settings at Administration > Configuration > Twitter > Settings (/admin/config/services/twitter/settings).

oauth keys

Add Twitter accounts

You can add Twitter accounts from Administration-> Configuration-> Twitter (/admin/config/services/twitter) or by editing a user account with permissions to add Twitter account. Note that at least you need to authenticate a Twitter account (which means that it is an account owned by you). Here is an example:

twitter_no_account.png

Click to add an account. Once again, verify that the list of permissions you are giving is correct in case you later want to Post to Twitter.

twitter_authorize.png

After authorizing you will see your account listed and you will be able to pull tweets and mentions from Twitter.com by activating the checkboxes and saving changes.

twitter_account_added.png

There is also a new textfield to add non-authenticated accounts (any other Twitter account from which you do not know its password). You can pull tweets from these accounts too but not mentions.

Troubleshooting

Could not obtain a valid token from the Twitter API

If you get the following error message after trying to authorize your Twitter account:

Could not obtain a valid token from the Twitter API. Please review the configuration.

Please check the following:

  • You have entered the right callback URL when creating the Twitter app. If you are testing on your local machine, this could be something like http://127.0.0.1:8000/twitter/oauth, or your local hostname: eg. http://mysite.local/twitter/oauth.
  • Make sure the OpenSSL extension is enabled in PHP. Edit php.ini and check that the following line is not commented out:
    extension=openssl.so

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

juampynr’s picture

Just wanted to thank all the editors of this page. Great work!

tuyre’s picture

I've got the Twitter module working well. I just can't find where to set the maximum number of messages displayed at any one time, if at all possible?

juampynr’s picture

Enable Views UI and then edit the number of elements listed at the Tweets view (or any other view listing tweets that you may have configured).

tuyre’s picture

Thanks juampy,

Views was already in use. The fact you mentioned it allowed me to find what i wanted.

For others these were the steps I took...

1) Home » Administration » Structure » Views
2) under Site Tweets view, click edit.
3) Click 'Block' (this may be page for some of you)
4) Under 'Pager' change 'Use Pager' to 'Display a specified number of items', and after applying, set to whatever.
5) Aplpy & Save view.

arlingtonvoicellc’s picture

I followed these instructions, but my view is only showing two tweets. Can someone explain why only the two most recent tweets are showing?

epe’s picture

I did all that and I can view the 7 latest tweets I want to show in the views preview of the block.
But the Block is not showing up in the structures>>blocks area.
I tried giving the rights to view this to everyone and even rename the block, no success so far.

nnmlss’s picture

I did everything explained here, a few times, from start to end, even delete and register apps again but all I achieve is I can receive my tweets in Drupal, but no any chance for drupal to twitter connection.........

if I try to post to twitter a submitted page on drupal, I receive in my drupal site a message that post to twitter is successful but no tweet in my account.

When I try to login with a twitter account, once I click on the login-with-twitter button I receive the next message

Whoa there!
There is no request token for this page. That's the special key we need from applications asking to use your Twitter account. Please go back to the site or application that sent you here and try again; it was probably just a mistake.

I try all of this in Drupal7 site, the 'green' Twitter and Oauth Drupal7 versions of the modules from drupal.org/project with a twitter.lib.php from the https://github.com/juampy72/twitter-rest-php/downloads library.

Any help will be appreciated...

juampynr’s picture

This should be better addressed at an issue. Please see http://drupal.org/node/1437628 and paste there your findings.

jekhor’s picture

Please add information about adding site-global twitter account. It is non-trivial.

crasher’s picture

Hi there, i have this all working with the exception that i must publish the node article to get it feeding to twitter. Can anyone suggest where i am going wrong here. I want to be able to create a node but not publish it on the web site but to post directly to twitter.

Any help or advice would be great.

Thanks

hanpersand’s picture

I appreciate this page a lot--it helped me get up and running. I made a streamlined set of instructions for setup now that we're at a place where OAuth is required to pull tweets. http://devcollaborative.com/5-days-left-replace-your-twitter-rss-feed-dr...

Thank you!

ibar’s picture

I have a news site where several users with the role Editor can post nodes. The newspaper has one Twitter account where I want all the nodes to be published to.

How can I do this? Currently only nodes created from the Administrator (in which account the twitter account was added) are ported to Twitter.

Thakns

symphonia’s picture

I followed all the steps correctly but I can't see any tweet.... do you have suggestion please?

dddave’s picture

FOLKS,

THE NOTES CLEARLY STATE THAT SUPPORT QUESTIONS DON'T BELONG HERE. GO TO THE FORUMS AND CHECK TWITTER MODULES ISSUE QUEUE!

kip stanning’s picture

i was looking for an answer on how you can let users add authenticated twitter accounts. i did everything right on permissions but didn't find the place where users can actually do it. found it now: it's on the edit-page of the user's account on my drupal site: if you open e.g. .../user/3/edit you find a tab TWITTER ACCOUNTS. i was searching on the tab TWITTER of the user's profile which shows - once an account is added - the tweets of that account.

hope that helps others.

thx everyone for the module, the handbook and all the work you're doing. really appreciate it.
kip

jozzy’s picture

Hi I am getting the following message on authentication of Twitter in Drupal.
"Could not obtain a valid token from the Twitter API. Please review the configuration."
Old websites (Late 2013) with the Twitter module originally authenticated to Twitter, however authenticating today(4th march 2014) I get this message.
I have tried all the above suggestions, also I have Openssl enabled in php.ini
I have copied the API key/Secret key, anyone else having trouble reauthenticating now?

sebto’s picture

Enabling write permissions is not possible sometimes. Twitter enforces to add a mobile phone in your twitter account profile. It would be easier to do this from Twitter app on your smart phone.

monstordh’s picture

The problem I had was that I was setting this up for a client and was currently logged into Twitter with MY Twitter account. I had to login with their account before this would work.

gbirch’s picture

When I had failed to enter the right callback URL, the module also threw PHP notices, which led me to assume that the failure to get a token was due to a bug rather than a mis-configuration. If the documentation mentioned the errors, they'd turn up in a google search, and perhaps save people time?

Giles Birch
Tech-Tamer.com

sprite’s picture

I followed the instructions above, using the defaults, and was able to get tweets displaying relatively quickly.
I've also updated the document above with the current URLs that twitter is using.

Notably, I had to perform the authorization step from my site's end a couple times after setting up the "app" on twitter.

I'm running ultimate cron. Thus I noticed that the twitter cron job needed to be manually run the first time to get it started.

Good documentation for modules on drupal.org really helps, when and where it exists.

There is a lot to be said for writing step by step recipes.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

sanoopuio’s picture

After twitter authentication , control is returned to drupal website and here it show

The requested page "/twitter/oauth?oauth_token=RAB6xAAAAAAAwGNbAAABWCjdqs8&oauth_verifier=lNs51gtXbIwTY3ghFSklD8YDEaFzgSg4" could not be found.

I have created a issue https://www.drupal.org/node/2824522

Thanks in Advance
Sanoop

Leeteq’s picture

I just struggled with this too, and it did not authenticate until I set the following without requiring callback (no tick mark), but still specifying a callback URL:

Web site URL: http://www.mydomain.com
Callback URL: http://www.mydomain.com/user/2/edit/twitter
That worked.

The documentation should also make it clearer that there is a twitter tab that is NOT visible among the normal user account tabs, but only visible when on the user EDIT page. (that is the one whose URL I used as the callback; for the user that the Twitter account belongs to. Not the similar page in the main Twitter settings in the admin section... (they look almost the same, which is confusing too.)

.
--
(A: Recruiting bi-lingual Spanish/English Drupal experts to http://CMX.content.cat
B: Inviting "minipreneurs" and DrupalExpert-wannabees to the same and related project(s).)