我想在android上創建一個flickr應用程序,但我堅持在請求令牌的身份驗證。Android Flickr Oauth invalid_signature同時獲取請求令牌
生成簽名
API密鑰:-496a8ac6ca46325e6cef * * ****
阿比揭祕:-685682a92 * **
基礎線: - GET&http%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3Dsoft%253A%252F%252Fcom.alice.testflickr%26oauth_consumer_key%3D496a8ac6ca46325e6cef%26oauth_nonce%3D394e61453f7b82cd633d229ac9b6454b%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1339654651%26oauth_version%3D1.0
生成簽名的方法: -
public String computeSignature(String baseString,String key)throws IllegalStateException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException{
//here key is the appsecret+"&"
byte[] byteHMAC = null;
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec spec = new SecretKeySpec(key.getBytes(),"HmacSHA1");
mac.init(spec);
byteHMAC = mac.doFinal(baseString.getBytes("UTF-8"));
return new String(Base64.encode(byteHMAC,Base64.NO_WRAP));
}
時間戳是(System.currentTimeMillis)/1000
隨機數是Long.toString(System.nanoTime());
我的請求令牌這樣的要求: -
http://www.flickr.com/services/oauth/request_token?oauth_nonce=12190496931948&oauth_timestamp=1339664498&oauth_consumer_key=496a8ac6ca46325e6cef&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=jg8CCdKb8gw%2BMJK0aJ6Brpba0G0%3D&oauth_callback=soft%3A%2F%2Fcom.alice.testflickr
但我總是最後得到
oauth_problem=signature_invalid&debug_sbs=GET&http%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3Dsoft%253A%252F%252Fcom.alice.testflickr%26oauth_consumer_key%3D496a8ac6ca46325e6cef%26oauth_nonce%3D12190496931948%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1339664498%26oauth_version%3D1.0
我的簽名方式有什麼問題,或者是否有其他問題? 編輯:於即basestring時間戳和請求的值相同