Android OAuth Invalid/Expired Token

I’ve been going over Marko Gargenta’s Learning Android book, published by O’Reilly Media; in it he goes through the creation of a basic Twitter app.  After struggling through the first example, I discovered two things:

  1. The examples in the book was using deprecated calls in the JTwitter library.  Twitter had moved away from simple authentication and now prefers OAuth
  2. The android emulator was running super slow

I was able to resolve the first issue by doing a bit of independent research into how OAuth works in Android.  I also switched over to the Twitter4J library as well.  I’ll make a post about that later as it was a bit of a discovery process to get it all working.

To address the speed issue, a Stack Overflow search gave me this useful post: Slow Android Emulator

Using those two bits, I managed to get things up and running at a decent speed.  Things were working great for a while until I started to get a mysterious Invalid/Expired Token exception whenever I tried to authenticate the application through OAuth calls.  After a bit of digging, I found out that the tokens that are issued via OAuth requests expire relatively shortly.  The problem was, I was requesting these tokens immediately!

After stepping back for a bit, I realized that the Android emulator snapshot that I was using to speed up the boot-up process was conflicting with the OAuth token acquisition and verification.  So the simple fix was to turn off Snapshots and use the Android AVD normally.

This entry was posted in Java, Tech and tagged , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

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


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>