0

Help me to build signature and request to delicious API

Hi,
I've made it all the way to Step 7 (http://delicious.com/help/oauthapi)

But keep getting
Please provide valid credentials.

I've spent literally two days trying to figure this out and haven't had any luck.

Can someone please paste their JAVA code where you build the base string, generate the signature, and request to delicious api(any common example)?

I would be soooooo thankful:)

I'm thinking I may be doing the urlencoding in the wrong order or something simple like that. Or maybe the headers I'm using in cURL aren't right. Or maybe the Delicious instructions are wrong (yet again...like in Step 4).


Here is my code:

These are my steps[5 to 7]

Step 5:

access_token=A%3DuV5zdJSbpQvlLxowAU0i675uUVbUUV_l6D6L5GKjxnSEykWLnvR9rrgsDkPpvWJdahxxbGl68DGEoc
uKMrcS_j1YULaae7Z_QfTPxN3iEkYfOKl96qAaYHdygRA35e.rhrdCrtLAxOoxW.nCblEga4pq0l9mxr_
rSkx64q2OJFLNyYTgXhir5kiw9JvlzevkKXyf3NMEAQaJqb5Fd8N0D4iXma4uWM5DIojJ8OM5wOwkB2Du
iRZ1n00F5S4Qg3BpkH2GrukQl.TMk4oAmQGGi341_.9rQRFzR_hCbVLZsNjzVB49ZQVqXw6oH47yrdgL5
ZzjieefTmhcWDFSHoo3CtiimGIve6U35cUH8cmBbrtSbUdA2yA19QREVbsmoKe3v_GoU0_6VFjBNCS1PB
_vYG82cJVB0ROibkX3udaKQe_VX.hKjSMyT.n78Z8YWUaKCwAGsBGw9yZP3XnlUjb_A72BrzMi5UDJaWw
r9_kWDCTPJ1YtUROdPWXSbUMZ33c.cradFdNmIMHW1hIwYgOCXSIRn1a2Yf6kTtCnP_1FD_oz06k.NQjB
pkMl7x4.Xsh6zLjG0hhEBYNO3AYeLk2lvPcXP2nzJQ4gmQ__Cz0ctHzDHayP47E0rQwGEDi0.wLBx0Bzf
Tx3GTh0trqNAUY.8dzLWgcjZya7OFzX3X1WxGMg9Tz5xegSRxYt.8aRyIp7kmfumKq67qpJ_CxbVWcZIp
ztN61N2A--

String[] arrTimeStampAndNonce = createTimeStampAndNonce();

String params = "oauth_consumer_key="+ServletConstants.YAHOO_CONSUMER_KEY+
"&oauth_nonce="+arrTimeStampAndNonce[1]+
"&oauth_signature_method=HMAC-SHA1"+
"&oauth_timestamp="+arrTimeStampAndNonce[0]+
"&oauth_token="+access_token+
"&oauth_version=1.0"+
"&url="+URLEncoder.encode("http://www.yahoo.com/","UTF-8");

String encodeParams = URLEncoder.encode(params,"UTF-8");

String encodeURL = URLEncoder.encode("http://api.del.icio.us/v2/posts/suggest", "UTF-8");

String baseString = "GET&"+encodeURL+"&"+encodeParams;

Result:

String baseString = "GET&http%3A%2F%2Fapi.del.icio.us%2Fv2%2Fposts%2Fsuggest&oauth_consumer_key%3Ddj0yJmk9UzQzbjNFZlpZdnJTJmQ9WVdrOVlXbFlVbGxrTnpRbWNHbzlOVFE1TXprME5EWXkmcz1jb2
5zdW1lcnNlY3JldCZ4PWVl%26oauth_nonce%3D5731531896143931081%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1293457885%26oauth_token%3DA%253DuV5zdJSbpQvlLxowAU0i675uUVbUUV_l6D6L5GKjxnSEykWLnvR9rrgsDkPpvWJdahxxbGl68DGE
ocuKMrcS_j1YULaae7Z_QfTPxN3iEkYfOKl96qAaYHdygRA35e.rhrdCrtLAxOoxW.nCblEga4pq0l9mx
r_rSkx64q2OJFLNyYTgXhir5kiw9JvlzevkKXyf3NMEAQaJqb5Fd8N0D4iXma4uWM5DIojJ8OM5wOwkB2
DuiRZ1n00F5S4Qg3BpkH2GrukQl.TMk4oAmQGGi341_.9rQRFzR_hCbVLZsNjzVB49ZQVqXw6oH47yrdg
L5ZzjieefTmhcWDFSHoo3CtiimGIve6U35cUH8cmBbrtSbUdA2yA19QREVbsmoKe3v_GoU0_6VFjBNCS1
PB_vYG82cJVB0ROibkX3udaKQe_VX.hKjSMyT.n78Z8YWUaKCwAGsBGw9yZP3XnlUjb_A72BrzMi5UDJa
Wwr9_kWDCTPJ1YtUROdPWXSbUMZ33c.cradFdNmIMHW1hIwYgOCXSIRn1a2Yf6kTtCnP_1FD_oz06k.NQ
jBpkMl7x4.Xsh6zLjG0hhEBYNO3AYeLk2lvPcXP2nzJQ4gmQ__Cz0ctHzDHayP47E0rQwGEDi0.wLBx0B
zfTx3GTh0trqNAUY.8dzLWgcjZya7OFzX3X1WxGMg9Tz5xegSRxYt.8aRyIp7kmfumKq67qpJ_CxbVWcZ
IpztN61N2A--%26oauth_version%3D1.0%26url%3Dhttp%253A%252F%252Fwww.yahoo.com%252F";


Step 6:

String hmackey = URLEncoder.encode(ServletConstants.YAHOO_CONSUMER_SECRET,"UTF-8")+"&"+URLEncoder.encode(access_token_secret, "UTF-8");

Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secret = new SecretKeySpec(hmackey .getBytes(), mac.getAlgorithm());
mac.init(secret);
byte[] digest = mac.doFinal(baseString.getBytes());
String hmacSignature =Base64.encode(digest);


Result :
hmacSignature: sgSo9U8Q7HKX5mlU0E6F6ezJkjc=

Step7:
hmacSignature = URLEncoder.encode(hmacSignature,"UTF-8");
String[] arrTimeStampAndNonce = createTimeStampAndNonce();

String params = "OAuth realm=\"yahooapis.com\",oauth_consumer_key=\""+ServletConstants.YAHOO_CONSUMER_KEY+"\",oauth_nonce=\""+arrTimeStampAndNonce[1]+"\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\""+arrTimeStampAndNonce[0]+"\",oauth_token=\""+access_token+"\", oauth_version=\"1.0\",oauth_signature=\""+hmacSignature+"\"";

String reqUrl = "http://api.del.icio.us/v2/posts/suggest?url="+URLEncoder.encode("http://www.yahoo.com/", "UTF-8");

GetMethod getMethod = new GetMethod(reqUrl);

getMethod.addRequestHeader("Authorization", params);


int status = httpclient.executeMethod(getMethod);

String bookmarks = getMethod.getResponseBodyAsString();


please guys help me... i am in big trouble for last 2 days..
Thanks,

by
0 Replies

Recent Posts

in OAuth General Discussion YDN SDKs