Skip to content

Posting to Twitter automatically using OAuth

Twitter recently switched off basic HTTP authentication, forcing developers to use the more complex (but hopefully safer) OAuth. There are lots of OAuth examples out there, but they all seem to focus on interactive apps, where the user is sent to Twitter to authenticate, and then the app uses the resulting access token to post on the user’s behalf.

However, for FuncNet we have a simple script running in a cron job, which posts a status message to @FuncNet every so often. This runs without any supervision, so I was left scratching my head as to how I could obtain the access token and access token secret required to post. The app registration page at for each app only shows its consumer key and consumer secret which are something different.

Eventually, thanks to Net::Twitter developer Marc Mims on this thread, I discovered that there’s a whole separate page for each app at which has the access token and access token secret required for the app to post to its own account.

N.B. In the URLs above, NNNNNN corresponds to the numeric ID for your application. If you don’t know what this is, just go to, click on the app name to get the consumer strings, and then click on My Access Token to get the access strings.

Once you have these, you can post like this (thanks again to Marc for example):

    use Net::Twitter;
    my $nt = Net::Twitter->new(
        traits => [qw/OAuth API::REST/],
        consumer_key        => $YOUR_CONSUMER_KEY,
        consumer_secret     => $YOUR_CONSUMER_SECRET,
        access_token        => $YOUR_ACCESS_TOKEN,
        access_token_secret => $YOUR_ACCESS_SECRET,
    $nt->update("Bob's your uncle!");

Why you need 4 distinct incomprehensible strings in order to post a single tweet, I don’t know, but presumably it’s justified on security grounds. What isn’t justified is Twitter hiding two of them somewhere else entirely, and not linking to that place from the main OAuth page for the app.

Not useful, guys.

UPDATE: It seems there are bigger problems with Twitter’s new process. This detailed ArsTechnica article describes OAuth 1.0a as “an inelegant hack” and Twitter’s implementation of it as being “against all reason”.

If you’re having trouble with it, you’re not alone; it seems almost designed to cause problems for app developers, and particularly open-source app developers. The article’s well worth a read.

Share/save this page:
  • email
  • Google Bookmarks
  • Twitter
  • FriendFeed
  • Digg
  • Reddit
  • StumbleUpon
  • Technorati
  • DZone
  • Slashdot
  • Fark
  • Facebook
  • MySpace
  • LinkedIn
  • Live
  • connotea

{ 7 } Comments

  1. loi Malraux | August 5, 2013 at 8:30 pm | Permalink

    We absolutely love your blog and find a lot of your post’s to be exactly what I’m looking for.
    Would you offer guest writers to write content to suit your needs?
    I wouldn’t mind creating a post or elaborating on most of the subjects you write related to here. Again, awesome web log!

  2. imvu free staff | September 11, 2013 at 10:30 am | Permalink

    dating Arrange meeting a expected is beauteous fiance fro you proper after breaking up.
    The person recommends that everyone should give it a try
    as they have nothing to lose by registering a free account.

    However, now things have taken a revolutionary turn for the best.

  3. cost-free | September 13, 2013 at 7:15 pm | Permalink

    People everywhere ‘ regardless of their phone type ‘ have needs
    for communication and entertainment. 0 – Liive Football The best soccer leagues
    from around the world are followed in this app.

    The Droid, Verizon Wireless and Motorola’s answer to the i – Phone, was
    only recently released to the public, but already, the Android Market is loaded with hundreds of free apps.

  4. Get IMVU Credit | September 16, 2013 at 9:42 pm | Permalink

    Check out my other article about imvu or go to for
    more information. Many roleplayers opt to have families
    and get married in these virtual worlds as well.
    You can even design and decorate your own room to invite other users to.

  5. Sertalig | December 13, 2013 at 5:24 pm | Permalink

    viagra economico
    generic viagra
    online order lilly viagra
    – generic viagra

  6. internet. | January 24, 2014 at 9:46 am | Permalink

    If you aree going for best contents like me, only visit this site eery day
    for the reason that it provides feature contents, thanks

  7. womens issues | March 1, 2014 at 7:13 am | Permalink

    Hi there, its nice article regarding media print, we all be aware of media is a
    great source of facts.

Post a Comment

Your email is never published nor shared. Required fields are marked *