【问题标题】:how to use token and secret in Oauth in android如何在android的Oauth中使用令牌和秘密
【发布时间】:2014-10-29 00:42:21
【问题描述】:

我在 Android 中使用 Signpost 进行 OAuth。

我得到 Http 状态码 500

也得到了

{"messages":{"error":[{"code":401,"message":"oauth_problem=parameter_absent&oauth_parameters_absent=oauth_signature_method"}]}}

代码如下:

            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");

//添加setsign方法。

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; }

【问题讨论】:

  • oauth_signature_method 丢失
  • 如何使用该方法“oauth_signature_method”
  • 请阅读手册。回复中已经提到了。
  • 能不能提供一下说明书的链接,你在说。

标签: android api oauth access-token


【解决方案1】:

Signpost 仅支持两种签名方法,即“PLAINTEXT & HMAC_SHA1”。但是,在您的情况下,您应该使用“HMAC_SHA1”。参考signpost中的SignatureMethod枚举。

通常您需要以下参数来签署请求

OAUTH_CONSUMER_KEY
OAUTH_CONSUMER_SECRET
OAUTH_SIGNATURE_METHOD
OAUTH_TIMESTAMP
OAUTH_NONCE
OAUTH_VERSION
OAUTH_TOKEN
OAUTH_TOKEN_SECRET

您可以在http://tools.ietf.org/pdf/rfc5849.pdf 找到有关 oauth 的更多详细信息

【讨论】:

    猜你喜欢
    • 2013-03-16
    • 1970-01-01
    • 2013-01-23
    • 2012-04-28
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    相关资源
    最近更新 更多