Using the TwitterApi 1.1 with TYPO3.Flow

By | 02/03/2014

Some days ago a tweet reached me where someone was asking what happened to my twitcode.org project. He had the need to tweet a code snippet and wanted to use my service. Since twitter canceled the support for the Twitter Api V1, my login via Twitter was not working any more. So I decided to invest some time for updating twitcode.org to the latest version of TYPO3.Flow and to update the Twitter Api to v1.1.

First of all I started to search for a twitter library that works and that is useable with TYPO3.Flow and I stumbled over a remake from Abrahams TwitterOauth on Github. Bad thing, it will not work with composer, so I continued my search. Then I found the Github account from Faruh Sibers, who splittet Abrahams library in smaller parts to make it work with composer. Bad thing, while writing this article, I just discovered that he deleted the repository. Lucky thing, I forked his library to make it work with TYPO3.Flow, so if you need it, check it out: TwitterApi.

So, now a short tutorial how to use the TwitterApi with TYPO3.Flow:

  1. First of all, add the consumer_key, consumer_secret and the callback to your Settings.yaml
  2. Inject these settings where you need it.
  3. Create the authorize URL to link to twitter:

    With this URL you can now build your button to link to the twitter login.
  4. Create a action that you define as your callback. Don’t forget to make the settings available here, I forgot it in the first place and was searching why there was no consumer_key available anymore.

    The callback will add two parameters to your callback URL, the oauth_token and the oauth_verifier. Use this parameter to create a new TwitterOAuth Object. Next step is to get the access token, which is required for all later actions and calls to the Twitter Api. The oauth_verifier is a temporary part in the token to get the real oauth_secret via curl. After you get the token with the oauth_token and oauth_secret, store them somewhere safe for all future calls to the Twitter Api.
    Now build, again, a new TwitterOAuth Object, but this time with the real oauth_token and oauth_verifier.
  5. Now you can use this TwitterOAuth Object to make all future calls to the API like shown on the Twitter Documentation

Thats it. Worked for me. There are a lot of people out there having trouble with the TwitterApi 1.1. Hopefully this helps someone.

Greetings,
Thomas

My fork of the TwitterApi: https://github.com/tlayh/TwitterApi
My composer file to add it: https://github.com/tlayh/Twitcode/blob/master/composer.json