TwitterX: MODX extra for Twitter feeds using API 1.1

DISCONTINUED: As Twitter no longer offers a free API to access tweet information, this extra is now discontinued and no longer supported. Thanks for using it.

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. Thanks Kevin, will sort this now and upload a new version :) stewart.orr
  2. Love the plugin! I ran across an error. The &limit property was adding one to the number I specified. For example, I wanted 3 tweets, entered &limit=`3`, but 4 would show. Specify 2, and 3 would show.

    In the snippet, there's a line:

    // Request statuses 
    $options = array(
    'count' => $limit+1,
    'include_rts' => 1

    I removed the +1 and it now displays the correct number specified in &limit.

    Thanks for the plugin, it's great!
    Kevin
  3. Hi Sarah, what version are you using? 0.6 is the best. Do you get any errors in the server log?
    twitter_consumer_token_secret is a mistake that I haven't changed as it would break anyone upgrading. stewart.orr
  4. Hi Stewart,

    I have changed back the 4th call to consumer_token_secret, but now the page loads blank (firebug console gives me 500 error) - this is my code:


    [[!TwitterX?
    &twitter_consumer_key=`consumer key`
    &twitter_consumer_secret=`consumer secret`
    &twitter_access_token=`access token`
    &twitter_consumer_token_secret=`access secret key`
    &limit=`1`
    &timeline=`user_timeline`
    &chunk=`TwitterXTpl`
    &cache=`7200`
    &screen_name=`twitter username`
    ]]


    Twitter gives me 2 consumer keys and 2 access keys and I have checked they are correct.

    Is there any reason why the secret access key is called
    &twitter_consumer_token_secret
    instead? wouldn't twitter expect this to be access_token_secret?

    Thanks. Sarah
  5. Hi Sarah, that looks incorrect it is expecting 4 parameters:
    &twitter_consumer_key=`1`
    &twitter_consumer_secret=`2`
    &twitter_access_token=`3`
    &twitter_consumer_token_secret=`4`


    Make sure you are passing those 4 values! stewart.orr
  6. Hi,

    I have tried to implement TwitterX on my ModX Rev 2.2.4 but get this error where tweets should be displayed:

    TwitterX Error: Could not load TwitterX as required values were not passed.


    I have the following call:

    [[!TwitterX?
    &twitter_consumer_key=`as created`
    &twitter_consumer_secret=`as created`
    &twitter_access_token=`as created`
    &twitter_access_token_secret=`as created`
    &limit=`1`
    &timeline=`user_timeline`
    &chunk=`TwitterXTpl`
    &cache=`7200`
    &screen_name=`twitter username`
    ]]


    Note: I have changed &twitter_consumer_token_secret= to &twitter_access_token_secret= as the consumer token was duplicate in the above code on here.

    Any help in finding a solution for the error greatfully received - finding a twitter feed that actually works is proving a mission! Thanks. Sarah
  7. Hi Louis, that's strange. Where are you testing this? If you are testing on a local environment you need to check that cURL is enabled as it is used to make the request. Let me know what you're testing on and I'll have a think. stewart.orr
  8. Thank you Stewart for the Update. I still don't understand what I'm doing wrong, it's not working for me for some reason. This is what I've done.

    - Uninstalled the previous version and installed the 0.6 version.
    - added the following to the location where I want to show the tweets.
     [[!TwitterX? 
    &twitter_consumer_key=`The Key I got from creating the App as per instruction`
    &twitter_consumer_secret=`The Key I got from creating the App as per instruction`
    &twitter_access_token=`The token I got from creating the App as per instruction`
    &twitter_consumer_token_secret=`The token I got from creating the App as per instruction`
    &limit=`4`
    &timeline=`public_timeline`
    &screen_name=`screen name for the tweeter account I want to display on the site`
    &chunk=`TwitterXTpl`
    &cache=`7200`
    ]]


    I have not touched the snippet nor the chunk, haven't modified any files at all and all I get is this "on twitter" with a hyperlink to twitter.com. Louis
  9. This has been submitted an approved now. Louis you can use &screen_name=`asdf` to load another user's tweets. You will need to download the latest version TwitterX 0.6pl stewart.orr
  10. Hi Louis, I am making a change to it now that allows you to view any users status. I will post here when it is live. It's strange that you are seeing .on twitter. Do you want to email me your code so I can look at it? stewart.orr
  11. Hello,

    I'm trying to get this to work and I followed the instructions step by step but it's not doing what it's supposed to do. It's not loading my tweets, all I see is a line that says ".on twitter" and nothing else.

    I'm also wondering if you have to create an APP for every twitter account you want to fetch status for or if there's a way to fetch any twitter account's status you want.

    Thanks. Louis
  12. How do I get someone else's feeds to load instead of mine? I can't even get mine to load. All I get is ".on twitter" to display on my website. Louis
  13. Hi Paul, I have just submitted a new version so that might explain why it is down at the moment. You can download it here and then FTP it to your MODX /core/packages/ folder. Then use "Search for local packages". Let me know how you get on! stewart.orr
  14. This looks great! However the download link on modx.com is broke for TwitterX, is there an alternative download location? Thanks. PaulG
  15. Hi Sanjuro. Currently this is not possible. It can only read one feed from Twitter at a time. stewart.orr
  16. Jeremy, thanks for this. Will get it updated ASAP! stewart.orr
  17. I just found the issue. Line 73 of the snippet needs to be changed from
    echo "TwitterX Error: Could not load TwitterX Twitter reponded with the error '" . $json['error'] . "'.";

    to
    echo "TwitterX Error: Could not load TwitterX Twitter reponded with the error '" . $json->error . "'.";
    Jeremy
  18. I am getting the following error:
    Fatal error: Cannot use object of type stdClass as array in /FULL/PATH/TO/core/cache/includes/elements/modsnippet/9.include.cache.php on line 78

    Any idea what is causing this? Jeremy
  19. Stewart Orr,
    then does not show my tweets (user_timeline)...
    I want to display my tweets (&timeline=`user_timeline`) and mentions (&timeline=`mentions`)
    Sanjuro
  20. Sanjuro, for mentions try this: -
    [[!TwitterX? 
    &twitter_consumer_key=`aaa`
    &twitter_consumer_secret=`bbb`
    &twitter_access_token=`ccc`
    &twitter_consumer_token_secret=`ddd`
    &limit=`4`
    &timeline=`mentions`
    &chunk=`TwitterXTpl`
    ]]
    stewart.orr
  21. Stewart Orr, I want to display my tweets and mentions
    p.s. please excuse my bad English... Sanjuro
  22. Sajuro, try using
    &timeline=`mentions`
    stewart.orr
  23. Hi,
    how to set up user_timeline + mentions? Sanjuro
  24. Hi Blair, I've just noticed I haven't updated the documentation on this page. Try using the placeholder retweet_text for the retweet. This should be without the ellipse. stewart.orr
  25. So, unless I'm doing something wrong, I'm noticing that the 'user_timeline' option doesn't include retweets, nor any method of including them. I modified my installed copy of TwitterX, changing the line
    $json = $twitteroauth->get('statuses/' . $timeline);

    to
    $json = $twitteroauth->get('statuses/' . $timeline, array('include_rts' => true));


    Which works, save that the retweets are truncated with an ellipses. I'll fiddle with it some more to see what I come up with. Blair Miller
  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>