(also see my related posts Tweeting with VBA and Twitter Timelines with VBA)

I’ve had a few inquiries/questions from people who have modified my VBA Twitter code, but have run into problems (namely, ‘401’ error responses when trying to authenticate). While I don’t promise the following will help absolutely everyone, I think it’ll prove useful.

When modifying the code to work with other Twitter APIs, you will likely have to pass additional parameters when creating your OAuth base string. Unfortunately, it doesn’t appear to simply be a matter of appending the new parameter to the end of the existing base string function! Depending on which API you’re using, Twitter seems to expect the base string parameters to be in a specific order. For example, when creating a base string for use with the statuses/update.json API, your base string parameters should be in the following order:

  • oauth_consumer_key
  • oauth_nonce
  • oauth_signature_method
  • oauth_timestamp
  • oauth_token
  • auth_version
  • status/li>

Now, say you wanted to modify the code for use with the statuses/user_timeline.json API. You might think you could just 1) remove the status parameter, and 2) append the count, exclude_replies, and screen_name parameters to the end. If you simply do that, you’ll likely get 401 error responses. Instead, the parameters must be ordered as follows:

  • count
  • exclude_replies
  • oauth_consumer_key
  • oauth_nonce
  • oauth_signature_method
  • oauth_timestamp
  • oauth_token
  • auth_version
  • screen_name

The easiest way to figure out what order parameters should be in for any particular API is to use the ‘OAuth Tool’ on your app’s page in your developer account.

toolbar

The tool will pre-populate your keys and tokens, so all you need to worry about is specifying the proper request type (GET, POST, etc…), URL for the API you’re using, and whatever API parameters you’ll be including.  So, if I wanted to generate a sample base string for a call to statuses/user_timeline.json with countexclude_replies, and screen_name parameters, here’s what I’d enter:

oauth_entry

When you click the ‘See OAuth signature for this request’ button, you’ll get a sample of the exact base string Twitter expects you to use.

oauth_result

After you have this sample, do a Debug.Print of your base string function, and make sure that the parameters in the string you’re creating are in the exact same order as what Twitter expects (don’t worry if the oauth_nonce and oauth_timestamp differ…the important part is the parameter order).

ADDENDUM (7/10/13) – I’ve been looking in Twitter’s documentation for a definitive statement re: parameter order. Haven’t found it yet, but I have found a couple of other blog posts that mention similar problems. So, I still strongly recommend that you construct your base string ordering your parameters in the same order as they appear on the OAuth tool.

One Thought on “Using Twitter’s OAuth Tool

  1. John Estill on July 8, 2013 at 12:45 pm said:

    Greg,
    Thank you for your speedy reply to my email! I have users/lookup running for my immediate needs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation