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 8581521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:04:22+00:00 2026-06-11T21:04:22+00:00

I am trying to generate a OAUTH signature from flicker.com. I had obtained the

  • 0

I am trying to generate a OAUTH signature from flicker.com. I had obtained the source code from:

Absolute minimum code to get a valid oauth_signature populated in Java or Groovy?

But when I am trying to execute it I am getting “The Constructor Base64() is not visible error”.

My class is:

public class MainActivity extends Activity {

    Button login;

    //---------------------------------------------



     static String key = "key";
     static String secret = "secret";

     static final String HMAC_SHA1 = "HmacSHA1";

     static final String ENC = "UTF-8";

      static Base64 base64 = new Base64();



     @SuppressWarnings("static-access")
    private static String getSignature(String url, String params)
             throws UnsupportedEncodingException, NoSuchAlgorithmException,
             InvalidKeyException {
         /**
          * base has three parts, they are connected by "&": 1) protocol 2) URL
          * (need to be URLEncoded) 3) Parameter List (need to be URLEncoded).
          */
         StringBuilder base = new StringBuilder();
         base.append("GET&");
         base.append(url);
         base.append("&");
         base.append(params);
         System.out.println("Stirng for oauth_signature generation:" + base);
         // yea, don't ask me why, it is needed to append a "&" to the end of
         // secret key.
         byte[] keyBytes = (secret + "&").getBytes(ENC);

         SecretKey key = new SecretKeySpec(keyBytes, HMAC_SHA1);

         Mac mac = Mac.getInstance(HMAC_SHA1);
         mac.init(key);

         // encode it, base64 it, change it to string and return.
         return new String(base64.encode(mac.doFinal(base.toString().getBytes(
                 ENC)), 0, 0, 0), ENC).trim();
     }








    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        login=(Button)findViewById(R.id.login_button);
        login.setOnClickListener(new OnClickListener() {

            public void onClick(View v)  {

 HttpClient httpclient = new DefaultHttpClient();
            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            // These params should ordered in key
            qparams.add(new BasicNameValuePair("oauth_callback", "oob"));
            qparams.add(new BasicNameValuePair("oauth_consumer_key", key));
            qparams.add(new BasicNameValuePair("oauth_nonce", ""
                    + (int) (Math.random() * 100000000)));
            qparams.add(new BasicNameValuePair("oauth_signature_method",
                    "HMAC-SHA1"));
            qparams.add(new BasicNameValuePair("oauth_timestamp", ""
                    + (System.currentTimeMillis() / 1000)));
            qparams.add(new BasicNameValuePair("oauth_version", "1.0"));

            // generate the oauth_signature
            String signature = getSignature(URLEncoder.encode(
                    "http://www.flickr.com/services/oauth/request_token", ENC),
                    URLEncoder.encode(URLEncodedUtils.format(qparams, ENC), ENC));

            // add it to params list
            qparams.add(new BasicNameValuePair("oauth_signature", signature));

            // generate URI which lead to access_token and token_secret.
            URI uri = URIUtils.createURI("http", "www.flickr.com", -1,
                    "/services/oauth/request_token",
                    URLEncodedUtils.format(qparams, ENC), null);

            System.out.println("Get Token and Token Secrect from:"
                    + uri.toString());

            HttpGet httpget = new HttpGet(uri);
            // output the response content.
            System.out.println("oken and Token Secrect:");

            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream instream = entity.getContent();
                int len;
                byte[] tmp = new byte[2048];
                while ((len = instream.read(tmp)) != -1) {
                    System.out.println(new String(tmp, 0, len, ENC));
                }
            }








            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public void makeAToast(String str) {
        //yet to implement
        Toast toast = Toast.makeText(this,str, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }



}
  • 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-06-11T21:04:24+00:00Added an answer on June 11, 2026 at 9:04 pm

    You can not instantiate Base64 class as it’s constructor is private. Check source of Base64(Line no. 740). You have static methods provided directly, you can call those directly as Base64.encode(string). Check doc

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

Sidebar

Related Questions

I am trying to generate an Oauth signature in order to authenticate an user
I'm trying to generate Java source code with JDT/AST. I now have MethodDeclaration and
I am trying to verify an OAuth signature generated in code against a known
Im trying to generate a color gradient using ColdFusion. My current code below works
I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>
I am trying to get Oauth working with the Google API using Python. I
Looking at Dwolla's API documentation and trying the oauth.php example code (code shown below)
Trying to call from an android client, using the signpost oauth libs. I generated
I am trying to use Google Oauth API to get userinfo. It works perfectly
I'm trying to make an authorized get request to api.twitter.com/1/followers/ids.xml It keeps returning 401

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.