Reinvent The Wheel

Round is nice, but we can do better!

TTwitter

This version of TTwitter was last updated on April 4th 2012 to fix the “401″ issue!

NOTICE:

You may have noticed a lack of code changes recently… this is for the following reasons:

  • Lua4Delphi version 2 is currently at the top of my development schedule… this is due to a shift towards the desire for, and requirement of, runtime scripting integration for Delphi applications with the Lua language.
  • TTwitter is being linked in with my Social Delphi project: a platform designed specifically for the production (and use) of Online Social Networking (such as Twitter and Facebook) Components. This means that TTwitter is being fully rewritten to make use of that back-end, and will be repackaged within the Social Delphi Suite. I apologize if this causes any disruption to your plans or intentions, however keep in mind that I am providing all of this absolutely free, and (aside from the generosity of Embarcadero Technologies) receiving essentially no support from other developers.

YOU SHOULD CONSIDER THIS VERSION OF TTWITTER TO BE DEPRECIATED! 

On November 24th 2011, I committed an update to the SVN. This update primarily adds a Delphi XE package.

The update was originally intended to address perceived changes in Twitter’s authentication process, however extensive testing proved that no changes were required. Those reporting 401 “unauthorized” errors when using TTwitter are receiving those almost certainly because the version of Indy they are using with their version of Delphi is too old and therefore unsupported. You need to install Indy 10 (the Readme file provides the URL to obtain that) for TTwitter to function properly.

What is TTwitter?

TTwitter is a Delphi component made to provide complete and simple integration of Twitter’s features into your Delphi application(s).

What can TTwitter do?

Simply create an instance of TTwitter, and your application(s) will be able to:

  • Read and receive Twitter Updates from yourself and others, and display the information in whatever manner you desire.
  • Post new Twitter updates from your application (procedurally if desired)
  • Perform searches on Twitter (using either standard keywords, or Hash Tags) and perform operations based on the results (display them or use them to automatically perform other desired tasks)
  • Create your own Twitter Client in Delphi
  • Create your own Twitter Bot in Delphi (great for providing business exposure to relevant entities on Twitter, and, by extension, all related social networking facilities)
  • Follow” and “Unfollow” other Twitter users

Put simply, TTwitter provides access to the full Twitter API, but with a clean and simple Class Wrapper designed to make it quick, easy, and – dare I say – fun!

Does TTwitter have any dependencies?

Yes, though all are freely available for virtually all Delphi versions (and are provided as standard in the latest versions):

  • TIdHTTP

How much does TTwitter cost?

TTwitter is 100% free, without exception! I am providing TTwitter to every Delphi developer completely free of charge, and Open Source. You may use it and change it however you wish, though you must leave the original (and unmodified) copyright notice in the source file(s) of any modified version(s) or derived works containing a significant portion of the original source.

Setting up your Twitter Application on your Account

Go to http://dev.twitter.com/apps and select to register an application. You should provide settings appropriate to your desired applications, but certain settings are specific (Application Type MUST be Browser at the moment, and the Callback URL can be your own domain name, but must not be blank)

See the image below which shows the exact current settings for my TTwitt3r (you cannot use “Twitter” in the app name) test app…

Twitter App Settings

TTwitter's Test App Settings

Where can I get TTwitter from?

Currently, TTwitter for Delphi is in a state of Open BETA. This means that it’s available for you right now, but with the understanding that it is far from complete, and therefore it is not recommended that you begin any public/commercial projects integrating TTwitter.

There are two ways to get TTwitter:

  • Public SVN repository (http://svn.lakraven.com:81/svn/OpenSource/TTwitter/USERNAME AND PASSWORD ARE BOTH “anon” WITHOUT THE QUOTES! – This is the recommended means of obtaining TTwitter. With SVN, you can quickly and easily obtain the latest release of TTwitter without having to download and extract another zip file.
  • Download TTwitter.zip (943 KB contains only sources, no binaries … Last updated: Wednesday 4th April 2012) – This .zip file will be updated regularly, but not as often as the SVN repository!

Subscribe to my blog’s RSS feed or Follow me on Twitter (@LaKraven) to remain informed on all updates and releases for TTwitter (and my other projects).

NOTE: This page will be updated in the near future to include much more detail… at the moment it serves as an alternative location to retrieve the latest BETA.

Should you find any bugs, have any suggestions, or wish to make any contributions, this page serves as “TTwitter Central” until the new website is ready for launch!

124 Comments

  1. in XE2 folder empty. is it same to use files in XE folder?

  2. Hi Simon,
    Still trying to get the demo working in XE2. I hope you can give me a hint how to get it going. I still get 401 errors and so I can’t login to Twitter.
    I registered an application at Twitters Developerssite and filled in everything as stated on this site. I got a consumerkey and a consumer secret as well as an Access Token ans an Access Token Secret. I filled the latter two in in AppDetails.ini. I filled in the Name I gave the application in the Twitter1 component. When I start with my twitter accountname and password, I allways get a 401. I also tried the consumerkey and -secret. Only 401s…
    I suppose you get this question a lot, but I hope you can help me get it going. The Delphi code is no problem, but I’m not familiar with twitter….

    Thanks, Ronald (@TweetsVanRonald)

    • Have you tried running the precompiled executable on the SVN with your app details in place? Also, you did not mention the CallbackURL, which is important!

      If the precompiled demo with your app details won’t work, then there MUST be something wrong with the configuration of your App on Twitter’s website… it’s literally the only thing it can possibly be. Keep in mind that the precompiled demo is confirmed to work (it DOES work…. 100% without issue), so if it won’t work with your App details, then SOMETHING MUST BE WRONG with those details or the configuration on Twitter’s website.

      Please remember that, if I can’t replicate the behaviour, I can’t solve the problem. I have been unable to find any way of making TTwitter give me a 401 on login when correct details are entered for the application’s profile.

      This is just one reason why I’ve abandoned this particular version of TTwitter! It APPEARS to behave differently for different people, and certainly behaves differently on different Delphi versions (because Indy is inconsistent). The new version won’t suffer from this!

  3. Why is the callback URL important? You can register apps without a callback URL with Twitter.

    I’ve got the newest Indy installed, and the latest revision from SVN, and it still throws 401s for me as well. Also, I would fully agree that Indy 9 is, while not “inconsistent”, bad. It never went into any of my applications since it would cause any app to fail memory leak testing. But Indy 10 is nice and stable. compared to Indy 9.

    I’ve written one OAuth protocol thing myself a year or two ago, and quite remember how difficult this was. And that in the end, I was to blame, even though it would’ve been easier to blame Indy or whatever ;)

    My details:

    ApiKey = Twitter OAuth Consumer Key
    ApiSecret = Twitter OAuth Consumer Secret
    (as an alternative, I also tried the access token and token secret)
    CallbackURL = Twitter Callback URL (updated twitter app to have one)
    Twitter OAuth access level = Read and write
    Twitter access token access level = Read and write
    TTwitter SVN revision 88
    Delphi XE Update 1
    Indy 10.5.7

    • The reason the Callback URL is used is two-fold: first of all, it’s because we’re making Twitter think our app is “browser-based” (to avoid the annoying PIN authentication stuff), and secondly it is the URL which tells the login form to disappear once auth is complete.

      I didn’t write the OAuth lib used by TTwitter, I merely modified it (the original attribution was unaltered in the OAuth unit) to work properly with XE.

      Honestly I do not know why some of you are getting 401 errors all the time! If I cannot replicate the problem, I cannot find a solution… so at the end of the day, some of the work has to be done by you guys! The more information I get about a problem, the easier it is to find and fix… but in this case there are so many points of failure beyond the control of my own code.

      • My problem with 401. it’s cause with characters with accents (eg. ò, à, á, …).
        I use XE and Indy 10.
        Thanks

        • Yes, this is another issue I’m aware of and working to resolve. I believe I may have something with converting Delphi’s UTF16 strings to UTF8, then encoding them into the URL string.

          • With Lua project, you think this problem will fix?, i’m fighting with TTwitter. It’s better to wait for new versión of Lua’s or, you needs some help. Is frustating this issue! :)
            thanks

          • I don’t understand the question. Lua4Delphi and TTwitter are entirely unrelated. Please take a look at my latest post (“TTwitter, GeNUI and Lua4Delphi – Dev Focus”) to see where I’m focusing my development efforts on the free/open source projects.

    • I found the problem with the 401 errors to be caused by using the http instead of https. Once I changed TWITTER_URL_BASE to https://api.twitter.com/%d%s, then the errors subsided. Hope this helps.

      Can read more about the issue here: https://dev.twitter.com/discussions/4545

      • I need to thank you for pointing this out. This particular issue appears to only occur when an account is set to use SSL (https) ONLY. An update has just been released based on this information.

        Everyone using this version of TTwitter owes you their gratitude :)

      • I am trying to find this update. I can get this to work in D2010, DXE but not DXE2 I keep getting the 401 error. Or help where is this change? I do like this component and hope to incorporate it in my next program and look forward to trying it in Firemonkey Thanks for any help

  4. I’ve made a twitter client in Delphi 7 using TTwitter.

    I just have to remove some redeclaration (overloaded) and all working fine!!!

  5. Pingback: TTwitter updated to fix “401″ bug | Reinvent The Wheel

  6. After I added the following code to the Twitter.inc file it worked with XE2

    {$IFDEF VER230}
    {$DEFINE DELPHI16} // Embarcadero RAD Studio XE2 (2011)
    {$DEFINE DELPHI15} // Embarcadero RAD Studio XE (2011)
    {$DEFINE DELPHI14} // Embarcadero RAD Studio 2010
    {$DEFINE DELPHI12} // CodeGear RAD Studio 2009
    {$DEFINE DELPHI11} // CodeGear RAD Studio 2007
    {$DEFINE DELPHI10}
    {$DEFINE DELPHI9} // Borland Development Studio 2006
    {$DEFINE DELPHI7}
    {$ENDIF}

    Also added {$I Twitter.inc} to the Twitter_Common.pas file.

  7. I am Delphi XE 2 with the new version and get Unathorized too.

  8. Just a question: everytime i run my application, do i have to authorize it?

    • Use one of the TokenStore components to store the OAuth token. This will then be used to retrieve the stored token so you won’t have to authenticate each time you run your application!

Leave a Reply

Required fields are marked *.

*


*