TwitterX: A new MODX extra for pulling in Twitter feeds using API 1.1

Since Twitter has now changed to enforce authentication, this new MODX extra loads Twitter statuses and timelines by using the new (and very annoying) Twitter 1.1 API.

TwitterX

Updated 01/12/2012 - Updated to allow for different screen names
Updated 04/11/2012
- Added some new changes and fixes.
Updated 12/11/2012 - Updated documentation.
Updated 16/01/2013 - Updated and slight improvements.
Updated 21/01/2013 - Added more options (thanks to sepiariver)
Updated 23/04/2013 - View the article here for more details, article below updated to reflect changes
Updated 12/06/2013 - Updated to use the 1.1 API (as it should have been) and a few other little things. Some things will no longer work on the 1.1 API.
Updated 12/01/2014- Added option to exclude_replies and small bug fix

View a demo on the homepage Download TwitterX


Getting started

  1. To get started, install the package using Package Manager in MODX. You will then need to create a Twitter app here: https://dev.twitter.com/apps/new

  2. Here create a new application by filling in the values required. Leave callback empty.

  3. How to create an application in Twitter

  4. Once you've created your application you will see there is a new API Key and API Secret.

    Your new twitter app will have an API key and API secret

  5. You will see a section called Your access token. Here you need to click Create my access token and the page will refresh with your new token,

    Create a new access token in your new twitter app

  6. Final step is to authorise your domain. I'm not 100% sure if this is needed but I was getting error message until I did this. Here you want to enter the domain of your site that is accessing the feed.

    How to create an application in Twitter


Usage

Once you've created your new application, have the necessary tokens and have authorised your domain you call the TwitterX snippet which will load your statuses using the details you have just generated:

[[!TwitterX? 
    &twitter_consumer_key=`aaaa`
    &twitter_consumer_secret=`bbbb` 
    &twitter_access_token=`cccc` 
    &twitter_access_token_secret=`dddd`
    &limit=`4`
    &timeline=`user_timeline`
    &chunk=`TwitterXTpl`
    &cache=`7200`
    &screen_name=`Qodo,Microsoft`
    &include_rts=`1`
]]

Parameters

  • twitter_consumer_key - your twitter consumer token (REQUIRED)
  • twitter_consumer_secret - your twitter consumer secret (REQUIRED)
  • twitter_access_token - your twitter access token (REQUIRED)
  • twitter_access_token_secret - your twitter access token secret (REQUIRED)
  • limit - limit how many statuses to display (default: 5)
  • timeline - which twitter timeline to load (default: user_timeline)
  • chunk - which chunk to load when rendering the statuses (default: TwitterXTpl)
  • cache - how many seconds to cache the twitter data feed (default: 7200)
  • screen_name - which user(s) you would like to load (comma separated) thanks to @hvoort
  • include_rts - should this include retweets (default: 1)
  • exclude_replies - should this exclude replies (default: 0)
  • cache_id - unique ID for caching in case you want to view multiple feeds or different feeds (default: TwitterX)
  • toPlaceholder - a placeholder ID if you want to use content as a placeholder instead of outputting directly (default: '')
  • search - search Twitter using a search value. When using this parameter, screen_name and timeline are ignored. (example: &search=`MODX`)

Loading timelines

The snippet defaults to user_time line but you can load any of these:

  • public_timeline
  • friends_timeline
  • user_timeline
  • home_timeline
  • mentions
  • retweeted_by_me this is no longer available in the 1.1 API!
  • retweeted_to_me
  • retweets_of_me

Searching Twitter

TwitterX now supports basic Twitter searches using the &search parameter:

&search=`MODX`

When using this parameter, screen_name and timeline are ignored.

TwitterXFormat

Use this snippet in your chunk placeholders to format the status text and automatically link any search, usernames or topics:

[[+text:TwitterXFormat]]

Chunk options

The package comes with a chunk for displaying the statuses called TwitterXTpl. You can customise this by using the following placeholders:

  • created_at - date status was created
  • source - source of the Tweet (application like web, iOS etc)
  • id - status id on Twitter
  • text - status main text
  • name - Twitter name
  • screen_name - Twitter username
  • profile_image_url - Twitter avatar image url for this user
  • location - This users location
  • url - This users URL (if specified)
  • description - This users profile information

And for retweets, you can use these

  • retweet_created_at - date status was created
  • retweet_source - source of the Tweet (application like web, iOS etc)
  • retweet_id - status id on timeline
  • retweet_id_str - status id on Twitter (twitter.com/user/statuses/id_str)
  • retweet_text - status main text
  • retweet_name - Twitter name
  • retweet_screen_name - Twitter username
  • retweet_profile_image_url - Twitter avatar image url for this user
  • retweet_location - This users location
  • retweet_url - This users URL (if specified)
  • retweet_description - This users profile information

Suggestions/Support

If you find any bugs or would like some help, please feel free to get in touch on GitHub: https://github.com/qodo/TwitterX


Comments 57

  1. Can you try again without the square brackets as MODX will remove these.... qodo
  2. It's TwitterXTpl with below html:

    anjana
  3. anjana, can you provide the chunk you are using? qodo
  4. I've installed this module and tried getting feeds having multiple screen names as:

    &limit=`5`
    &timeline=`user_timeline`
    &chunk=`TwitterXTpl`
    &cache=`7200`
    &screen_name=`aa,bb,cc,dd`
    &include_rts=`1`

    but it doesn't show the complete tweet description that includes image as well. How can I get the tweet text with the image included in the text? anjana
  5. Hi LK.

    No this should still work. It's not been updated as nothing has changed. I still use this on my website. Let me know what the errors are and I'll try and help. qodo
  6. Hi,

    I've used this extra before in the pass with great success but I seem to be struggling with it now and I'm getting authentication errors on the frontpage. I've populated and generated all the necessary fields. I have noticed this hasn't been updated for a little while though, is there any updates that we need to be aware of?

    Thanks,
    LK
  7. Thanks Hugo! qodo
  8. Hi Stewart,

    I was getting an error when using the &timeline=`mentions` property, and found out that it actually has to be mentions_timeline: https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline

    I guess they changed that in the API.. Hugo Peek
  9. Wow! ok you can ignore my previous comment. I figured it out () and I receive 319x319px images! A bit large, 72px would be better, but I can reduce them and the sharpness is back.
    Thanks. Gavin Alexander
  10. Thanks Stuart. Where should I find/add this? I've searched the online docs, my tpl and the snippet, and it's not in my snippet call either. I only have . Gavin Alexander
  11. Hi @Gavin

    By default the Twitter API returns the smaller image. One thing you could do here is replace the _normal with nothing which returns the full size:

    [[+profile_image:replace=`_normal==`]] qodo
  12. OK, I solved my avatar problem by using a modx output modifier, based on the retweet_name placeholder being set or not, then displaying tweet/retweet placeholders appropriately.

    My next query regards the avatar images.

    For some reason, these display the same size, but are much less sharp than the same avatars in the official twitter feed widget. Opening the images from each in a new tab shows the official twitter one to be 73x73px, while the TwitterX one is 48x48px. Both are displayed at 48x48px, hence the better sharpness of the official one.

    Is there any way I can retrieve the avatars at the larger size?



    Gavin Alexander
  13. Hi Stewart,
    thanks for this extra, it's great. I'm using it in Revo 2.3.5.
    A question re retweets: should I use the retweet placeholders in the same template (eg the default 'TwitterXTpl', or do I need to set up a separate template for retweets?

    Using it out of the box , with the snippet call as follows:


    I get retweets but with the avatar image of the retweeter. How can I show the avatar of the tweet's original tweeter instead (as the official Twitter feed widget does)? Gavin Alexander
  14. @Lee I could change this to add a new placeholder that makes it easier to see if this is the first Tweet if that would help? qodo
  15. @Carrrven No, not currently. The Twitter API only returns the smaller image location. This would require another call to load the various image sizes. qodo
  16. Is there a way to use a separate chunk template for the first tweet, i'm trying to use a carousel and need an active state on the first post? Lee
  17. profile_image_url - It produces only small 72x72 image . Is it possible to somehow change to 400x400 ? Carrrven
  18. @Mike Harvey: I have updated the extra to now have the option include_rts so you can turn these off. qodo
  19. This is a great addon. How can I not display retweets? Mike Harvey
  20. Actually n/m I added Favorites timeline support starting line 80 in the gist. The API docs don't seem to have the correct URL..? Anyways this works in my setup but it probably could use a boatload of testing :P

    One thing I noticed is the calls to MODX cacheManager are caching in the "default" partition right now. Might be a good idea to have them in resource/web/resources/{id}/ where {id} is that of the calling resource.

    TBH I gotta dig through the docs to figure how exactly to do that but thought I'd just throw it out there. Not totally necessary. The Addon is Awesomesauce, dude! YJ Tso
  21. Hey Stewart I added a couple of properties to the snippet to allow setting a custom cache ID (for calling the snippet more than once on a page) and to allow the option of outputting to a placeholder. The gist is here, with comments: https://gist.github.com/4560496

    One Feature Request I have, which is kind of beyond me to implement atm, is support for a Favorites timeline.

    Again, awesome work! :) YJ Tso
  22. Nice work! This is a great addon :) Vive la MODX! YJ Tso
  23. New version released.
    @Jeremy, I have added a check to see if CURL is available on your server. Are you getting the feed back correctly with results? If so, it sounds like the chunk template has a problem? Let me know if I can help. qodo
  24. There is a typo, in the statement "Could not load TwitterX Twitter responded with the error" responded is misspelled. Also I get no error and no tweets with TwitterX version 0.6 and ModX Rev 2.2.6. I tried removing the tokens and i do see the error message so I know I have it placed correctly on my page but there are no errors that display. I added a few echos and its running but no data.. no error messages... any ideas why?
    Jeremy
  25. Hi Stewart, Thanks. I'm using 0.6 (downloaded 4th Dec)

    Checked the server logs and it was the OAuth.php file (I edited as per Laurent's comment). I'm more of a designer than developer!

    However, I now just have an 'on twitter' link (link to twitter.com) displayed where tweets should be - just like Louis' on the comments above.

    Any ideas? I know when I have used the twitter widget from twitter itself, i have to include both the domain, and the domain with www.

    I have added both to the @anywhere domains in the dev app settings but still nothing... Sarah
  1. 1
  2. 2
  3. 3

Got something to say?

Join the discussion! You know how these things work; enter your details and comments below and be heard.

  1. Allowed tags: <b><i><br>