Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4613892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:37:08+00:00 2026-05-22T01:37:08+00:00

I have some simple code I am using to learn OAuth authentication using the

  • 0

I have some simple code I am using to learn OAuth authentication using the signpost library. I am trying to save the request token, the token secret and the pin as Java preferences, using java.util.prefs.Preferences. Putting the data into the preferences works fine (I check that the file is created and the information stored). However, immediatelly after I put() the data into the Preferences file, I try to check if the node exists, and I always get false.

I also tried just re-running the code, and checking for the node’s existence before I try to save the data again, and I still get false.

What am I doing incorrectly?

Here is the code:

package com.example;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.prefs.Preferences;

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;

public class ReadMain {

    public static void main(String[] args) throws Exception {

        OAuthConsumer consumer = 
        new DefaultOAuthConsumer(
                "??",
                        "??");

        OAuthProvider provider = 
        new DefaultOAuthProvider(
            "https://www.readability.com/api/rest/v1/oauth/request_token/",
                    "https://www.readability.com/api/rest/v1/oauth/access_token/", 
                    "https://www.readability.com/api/rest/v1/oauth/authorize/");

        System.out.println("Fetching request token from Readability...");

        Preferences prefs = Preferences.userNodeForPackage(ReadMain.class);

        final String PREF_TokenSecret    = "com/example/TS";
        final String PREF_RequestToken   = "com/example/RT";
        final String PREF_ReadabilityPin = "com/example/RP";

        boolean exists = 
            prefs.nodeExists( PREF_TokenSecret ) &&
        prefs.nodeExists( PREF_RequestToken ) &&
        prefs.nodeExists( PREF_ReadabilityPin );

        if ( prefs.nodeExists( PREF_TokenSecret ) )
        {
        System.out.println("Token secret exists!");
        }

        if ( prefs.nodeExists( PREF_RequestToken ) )
        {
        System.out.println("Request token exists!");
        }

        if ( prefs.nodeExists( PREF_ReadabilityPin ) )
        {
        System.out.println("Readability pin exists!");
        }

        String pin;

        if ( exists )
        {
        consumer.setTokenWithSecret( 
                prefs.get(PREF_RequestToken,""), 
                prefs.get(PREF_TokenSecret,"") );
            pin = prefs.get(PREF_ReadabilityPin,"");
        }
        else
        {
        // we do not support callbacks, thus pass OOB
        String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);

        System.out.println( "Request token: " + consumer.getToken() );
        System.out.println( "Token secret: " + consumer.getTokenSecret() );

        prefs.put( PREF_RequestToken, consumer.getToken() );
        prefs.put( PREF_TokenSecret,  consumer.getTokenSecret() );

        System.out.println( "Now visit:\n" + authUrl + "\n... and grant this app authorization" );
        System.out.println( "Enter the PIN code and hit ENTER when you're done:" );

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        pin = br.readLine();

        prefs.put(PREF_ReadabilityPin, pin);

        if ( prefs.nodeExists( PREF_TokenSecret ) )
        {
            System.out.println("Token secret exists!");
        }

        if ( prefs.nodeExists( PREF_RequestToken ) )
        {
            System.out.println("Request token exists!");
        }

        if ( prefs.nodeExists( PREF_ReadabilityPin ) )
        {
            System.out.println("Readability pin exists!");
        }
        }

        System.out.println("Fetching access token from Readability...");
        provider.retrieveAccessToken(consumer, pin);

        System.out.println("Access token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());

        URL url = new URL("https://www.readability.com/api/rest/v1/bookmarks?user=marcusps&archive=1");
        HttpURLConnection request = (HttpURLConnection) url.openConnection();

        consumer.sign(request);

        System.out.println("Sending request to Readability...");
        request.connect();

        System.out.println("Response: " + request.getResponseCode() + " "
            + request.getResponseMessage());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:37:09+00:00Added an answer on May 22, 2026 at 1:37 am

    The opposite operation of put(..) is get(..). So:

    boolean exists = prefs.get(key, null) != null;
    

    the get(..) method returns the 2nd argument if there is nothing found under the specified key.

    the nodeExists() is related to the hierarchical structure of preferences, and can be used when you’ve used prefs.node(..) to create a node. But you seem to need a flat structure, so you don’t need hierarchies, I think.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have some sample code showing how to POST to a URL using
I have some very simple code to generate an assembly and invoke a method
I have some code I've written in PHP for consuming our simple webservice, which
Currently, I have some basic code to play a simple tone whenever a button
I have a fairly simple const struct in some C code that simply holds
I have a simple form with some plain html input like bellow using ASP.NET
Hi We have some php code using the file_get_contents() function, and I understand this
I am new to Java and have been trying to make some simple games
I have some simple shell scripting tasks that I want to do For example:
I have some funny deadlock caused by a stupid simple SQL UPDATE query, on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.