Twitter OAuth Echo Java


#1

Whenever I try to connect with twitpic through OAuth Echo. I keep getting an error saying that my key was not provided: {“errors”:[{“code”:401,“message”:“Could not authenticate you (no application key provided).”}]}

I think that I am providing the key:
URL u = new URL(“http://api.twitpic.com/2/upload.json”);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod(“POST”);
conn.setRequestProperty(“X-Auth-Service-Provider”, echo.getXAuthServiceProvider());
conn.setRequestProperty(“X-Verify-Credentials-Authorization”, api.encode(echo));

conn.setRequestProperty(“key”, echo.getKey());
conn.setRequestProperty(“message”, echo.getMessage());
conn.setRequestProperty(“media”, echo.getMedia());
conn.setRequestProperty(“Content-Type”, “multipart/form-data”);
String urlParameters = “?key=” + echo.getKey() + “&message=” + echo.getMessage() + “&media=” + echo.getMedia();
DataOutputStream wr = new DataOutputStream(conn.getOutputStream ());
wr.writeBytes (urlParameters);
wr.flush ();
wr.close ();

//System.out.println(conn.getRequestProperties().toString());
// conn.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
System.out.println("Credentials Authorization " + api.encode(echo));
String line = “”;
System.out.println(“We’re printing things " + echo.getKey());
while((line = reader.readLine()) != null)
System.out.println(“Responseo " + line);
reader.close();
This is what the request headers look like. The consumer key and token are not correct here on purpose: OAuth realm=“http://api.twitter.com/”, oauth_consumer_key=“lFnSvJK5qYDevKId7wQ”, oauth_token=“322376460-g8h9go1QuoEv0PaKS6xmYw51vkkuEDdvvOE3Io”, oauth_signature_method=“HMAC-SHA1”, oauth_signature=”%D1BS|%C0%AF%C1%24%d9%3Es %F1%?2%E6%?4_%D8%B7”, oauth_timestamp=“1314708762”, oauth_nonce=“1314708762369660000”, oauth_version=“1.0”

This is the function that I am using for the hmacsha1:
public static String hmacSha1(String one, String two){

try {
one = percentEncoder.escape(one);
two = percentEncoder.escape(two);
Mac mac = Mac.getInstance(“HmacSHA1”);
SecretKeySpec secret = new SecretKeySpec(one.getBytes(),“HmacSHA1”);
mac.init(secret);
byte[] digest = mac.doFinal(two.getBytes());
return new String(digest);

} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}


#2

Here’s the StackOverflow link http://stackoverflow.com/questions/7247956/twitpic-oauth-echo-java-j2ee