Failing to getAccessToken with Signpost and Discogs

87 views
Skip to first unread message

Paul Taylor

unread,
Mar 25, 2014, 5:35:32 PM3/25/14
to signpos...@googlegroups.com
I'm trying to use Java SignPost to get Oauth support from Discogs

If I call this method it provides a url to a website, then if I login I get a verification code, so far so good.

        public static String requestDiscogsAuthorization() throws Exception
        {
   
            OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
            OAuthProvider provider = new DefaultOAuthProvider(
                    "http://api.discogs.com/oauth/request_token",
                    "http://api.discogs.com/oauth/access_token",
                    "http://www.discogs.com/oauth/authorize");
            provider.setRequestHeader("User-Agent", SongKong.USER_AGENT);
            return provider.retrieveRequestToken(consumer,  OAuth.OUT_OF_BAND);
        }

I store this verification code in my application and can retrieve as UserPreferences.getInstance().getDiscogsAuthorization(). So now I want to sign a url I try and call the getAccessToken() below to get an access code from my verification key but I get

oauth.signpost.exception.OAuthExpectationFailedException: Authorized request token or token secret not set. Did you retrieve an authorized request token before?



     public class DiscogsAuth
    {
        /**
         * Constructs a consumer with valid access token for signing urls (can only be used once user has authorizaed application and auth code
         * available to application somewhere
         *
         * NOTE:Not thread safe, has to be done once for each thread
         *
         * @return
         * @throws Exception
         */
        public static OAuthConsumer getAccessToken() throws Exception
        {
            OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
            OAuthProvider provider = new DefaultOAuthProvider(
                    "http://api.discogs.com/oauth/request_token",
                    "http://api.discogs.com/oauth/access_token",
                    "http://www.discogs.com/oauth/authorize");
            provider.setRequestHeader("User-Agent", SongKong.USER_AGENT);
            provider.retrieveAccessToken(consumer, UserPreferences.getInstance().getDiscogsAuthorization());
            return consumer;
        }
   
        /**
         * Sign Url Connection
         *
         * @param urlConnection
         * @param consumer
         * @throws Exception
         */
        public static void signUrl(HttpURLConnection urlConnection, OAuthConsumer consumer) throws Exception
        {
             consumer.sign(urlConnection);
        }
    }
Reply all
Reply to author
Forward
0 new messages