0

I am new to flickr API.Some where i get the code to create the signature for getting request token.but i cant able to create it for the access token.Always says that the signature is invalid.

i am using the code for creating signature is

private static String getreqSignature(String url, String params)
            throws UnsupportedEncodingException, NoSuchAlgorithmException,
            InvalidKeyException {
    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 = (ApplicationContext.getFLICKR_API_SECRET() + "&")
                    .getBytes(ENC);

            SecretKey key = new SecretKeySpec(keyBytes, HMAC_SHA1);

            Mac mac = Mac.getInstance(HMAC_SHA1);
            mac.init(key);
            System.out.println(new String(base64.encode(mac.doFinal(base.toString()
                    .getBytes(ENC))), ENC));
            // encode it, base64 it, change it to string and return.
            return new String(base64.encode(mac.doFinal(base.toString().getBytes(
                    ENC))), ENC).trim();

}

My query parameters are

qparams.add(new BasicNameValuePair("oauth_consumer_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 = getreqSignature(URLEncoder.encode(
            "http://www.flickr.com/services/oauth/request_token", ENC),
            URLEncoder.encode(URLEncodedUtils.format(qparams, ENC), ENC));



    // qparams.add(new BasicNameValuePair("oauth_verifier", verifier));
    qparams.add(new BasicNameValuePair("oauth_signature", signature));

    URI uri = URIUtils.createURI("http", "www.flickr.com", -1,
            "/services/oauth/request_token",
            URLEncodedUtils.format(qparams, ENC), null);

How to create signature to get access token.What to change in the above code.

4

1 回答 1

0

最后我使用 Scribe 库来获取我的详细信息。它工作正常。

于 2013-08-06T09:05:13.307 回答