5

I am using Play Framework and play.libs.OAuth, trying to connect to Twitter using the following code:

public static void twitterConnect()
{
    Response response;
    ServiceInfo twitterServiceInfo = new ServiceInfo(
        "https://api.twitter.com/oauth/request_token",
        "https://api.twitter.com/oauth/access_token",
        "https://api.twitter.com/oauth/authorize",
        "ZA*****************Dw",
        "Zy*************************************U4");

    if(OAuth.isVerifierResponse()) {
        // ...
    } else {
        OAuth twitter = OAuth.service(twitterServiceInfo);
        response = twitter.retrieveRequestToken(); <-- NOT WORKING!!!
        redirect(twitter.redirectUrl(response.token));
    }
}

but at the line marked <-- NOT WORKING!!!; I am getting the following error:

OAuth.Error: NOT_AUTHORIZED - Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.

I've double checked my consumer keys and secrets, as well as the request, access and authorize URLs, but to no avail.

Any ideas as to what is wrong with my code?

Jonas
  • 121,568
  • 97
  • 310
  • 388
josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157
  • Reading some documentation, but I think this approach is missing all the goodies that include the signature for authenticating with Twitter. – josef.van.niekerk Aug 31 '11 at 21:35
  • I am experiencing exactly the same problem. It is strange that no one came up with a sufficient answer. Guess, I should try that Scribe library as well – Preslav Rachev Nov 05 '13 at 11:05

2 Answers2

1

I ripped out the OAuth code, and reimplemented using the Scribe library written by Fernandez Pablo. Seems I'm getting further now. :)

josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157
-1

Apply a new twitter oauth key and secret with Callback URL may solve the problem.