I'm using Signpost for OAuth in android.
I am getting Http status code 500
and also getting
{"messages":{"error":[{"code":401,"message":"oauth_problem=parameter_absent&oauth_parameters_absent=oauth_signature_method"}]}}
Here are the codes:
client = new DefaultHttpClient();
ArrayList<NameValuePair> requestParaRegister = new ArrayList<NameValuePair>();`enter code here`
requestParaRegister.add(new BasicNameValuePair("firstname",_firstName));
requestParaRegister.add(new BasicNameValuePair("lastname",_lastName));
requestParaRegister.add(new BasicNameValuePair("username",_username));
requestParaRegister.add(new BasicNameValuePair("email", _emailID));
requestParaRegister.add(new BasicNameValuePair("password",_password));
HttpPost postRequest = new HttpPost("http://*************************/customers");
//added setsign method.
consumer.setMessageSigner(new OAuthMessageSigner() {
@Override
public String sign(HttpRequest arg0, HttpParameters arg1)
throws OAuthMessageSignerException {
// TODO Auto-generated method stub
return OAuth.percentEncode(CONSUMER_SECRET) + "&"
+ OAuth.percentEncode(_tokenSecret);
// consumer.setMessageSigner(OAuth.percentEncode(CONSUMER_SECRET));;
}
@Override
public String getSignatureMethod() {
// TODO Auto-generated method stub
return null;
}
getOauthConsumer().sign(postRequest);
public OAuthConsumer getOauthConsumer() {
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
consumer.setTokenWithSecret(_token, _tokenSecret);
return consumer; }
Signpost only supports two sugnature methods which are as "PLAINTEXT & HMAC_SHA1". However in your case you should use "HMAC_SHA1". Refer to the SignatureMethod enum in signpost.
In general you need the following params to sign the request
OAUTH_CONSUMER_KEY
OAUTH_CONSUMER_SECRET
OAUTH_SIGNATURE_METHOD
OAUTH_TIMESTAMP
OAUTH_NONCE
OAUTH_VERSION
OAUTH_TOKEN
OAUTH_TOKEN_SECRET
You can find out more details about oauth at http://tools.ietf.org/pdf/rfc5849.pdf
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.