Blog Post

Sheffield Apprenticeships - Using TwitterOAuth to post Tweets to the Twitter API


Our Sheffield Apprenticeship Twitter account (@SheffApprentice) uses the Twitter API to automatically Tweet out information about apprenticeship vacancies in Sheffield. The Tweets are scheduled - 6 individual apprenticeship vacancy Tweets and two summary Tweets every day.

Using the Twitter API is straightforward. You create your Twitter account, sign-up on the Twitter developer portal and then create your Twitter app. Creating the Twitter app generates your authentication tokens. That whole process takes just a few minutes.

We use TwitterOAuth to make the API calls. It is the most popular PHP library for the Twitter OAuth REST API and again, using TwitterOAuth is straightforward - it comes with excellent documentation.

Here’s how we use TwitterOAuth to make the API calls:

Using the Twitter API

A couple of things are worth noting:

  1. We use a function - getStatus() to build the Tweet.

  2. There is some basic error handling. We noticed that the most common error code, at least at the start, was ‘187’ - that means Twitter thinks you’ve just tried to post a duplicate Tweet. The error handling for that is simple - we get another Tweet from getStatus() and try again.

@SheffApprentice ticks over with very little maintenance though we did tweak the CRON job a bit at the start when it became clear that Tweets get more impressions at certain times of the day (and weekends). The number of followers is still low (we pick up one or two a day) but we get a reasonable number of retweets from people in and around Sheffield and we’re up to 70K impressions in just 3 weeks.

You can follow Sheffield Apprenticeships here:




Related Posts