Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error 401 trying to connect to Twitter with play.libs.OAuth

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?

like image 759
josef.van.niekerk Avatar asked Nov 26 '22 09:11

josef.van.niekerk


1 Answers

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

like image 135
josef.van.niekerk Avatar answered Nov 27 '22 22:11

josef.van.niekerk