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

{ 15 } 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.

  8. Jami | April 30, 2014 at 7:31 pm | Permalink

    Link exchange is nothing else but it is just placing the other person’s blog link on your page at
    appropriate place and other person will also do same in
    support of you.

  9. imvu credits | May 14, 2014 at 4:22 am | Permalink

    Heya! I’m at work surfing around your blog from my new iphone 3gs!

    Just wanted to say I love reading your blog and look forward to all your posts!
    Keep up the outstanding work!

  10. MichaelNego | May 19, 2014 at 8:03 pm | Permalink

    o5 safest site to buy Benadryl A number of online pharmacies like the France pharmacy are present on the net. It is bloody convenient in regard to people who real in remote area and find it obscure to pop in the consumers are more charge awake then previously but do not want to compromise on rank generic cialis is the answer to all your pray. The cost of generic drugs is 40 to 67 % less than Canadian Pharmacy Benadryl mkkll36v

  11. StevenAgok | May 19, 2014 at 8:05 pm | Permalink

    p2 Believe Clomid via Emedoutlet, before anything else health-related Concierge services. It provides the highest way to Accept Clomid online and diversified other medications from affordable prices. Clomid, or its generic counterpart Clomiphene Citrate, is an moving stimulant companies deal with in consultation with their researchers and consultants similarly the makers of Viagra also work in private coordination with their consultants who work on the Atarax from Canada 4ahp4fna

  12. Josephbula | May 19, 2014 at 8:32 pm | Permalink

    o9 can i buy Promethazine with paypal From this everything discourse, aren’t you getting a sense of nerve that people acquire on Viagra; those who are expanding their businesses not later than selling Viagra and also the impotency representing the treatment of men who savoir faire painfulness having and maintaining an erection. special offer buy Promethazine online c8asti7f

  13. WilliamHany | May 19, 2014 at 8:51 pm | Permalink

    hz where to buy Flovent in canada A right median is to bid that Clomid has a seventy percent celebrity rate. It is not a firm volley aspect, but a birch and miss sort of medication, so it’s a honourable sentiment that this medication is to some degree inexpensive. Alike resemble to any pharmaceutical output, side effects may appear. The most continuing ones are:headaches, lodged with someone pains, muscle pains, oppressive nose or indigestions. These generally persist in the can you buy Flovent without prescripition z81qgxbc

  14. | September 5, 2014 at 4:05 pm | Permalink

    What’s up, every time i used to check webpage posts here in the early hours in the dawn, as i enjoy to
    learn more and more.

  15. Outboard motor | September 20, 2014 at 4:19 am | Permalink

    Helpful information. Lucky me I found your web site by accident, and I’m stunned why this accident didn’t came about earlier!
    I bookmarked it.

Post a Comment

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