Java
Chilkat2 Java
Generate OAuth 1.0 Signature
Demonstrates how to generate an OAuth 1.0 signature.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.OAuth1;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
success = false;
OAuth1 oauth = new OAuth1();
// Set input parameters:
oauth.setOauthVersion("1.0");
oauth.setOauthMethod("GET");
oauth.setOauthUrl("http://echo.lab.madgex.com/echo.ashx");
oauth.setConsumerKey("key");
oauth.setConsumerSecret("secret");
oauth.setToken("accesskey");
oauth.setTokenSecret("accesssecret");
oauth.setNonce("01020304050607080102030405060708");
oauth.setTimestamp("1441659763");
// Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
oauth.setSignatureMethod("HMAC-SHA256");
try {
oauth.generate();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Examine the various outputs:
System.out.println(oauth.getQueryString());
System.out.println(oauth.getBaseString());
System.out.println(oauth.getHmacKey());
System.out.println(oauth.getSignature());
System.out.println(oauth.getEncodedSignature());
System.out.println(oauth.getAuthorizationHeader());
System.out.println(oauth.getGeneratedUrl());
}
}