2012-04-16 80 views
0

AT這兩個網站,他們要求令牌祕密和消費者的祕密: http://oauth.googlecode.com/svn/code/javascript/example/signature.html http://developer.netflix.com/resources/OAuthTest#instructions如何在OAuth中設置令牌機密和使用者密碼?

如何設置他們編程:

public void excecuteSigning(String targetURL){ 
      HttpRequestAdapter requestSig = new HttpRequestAdapter(new HttpGet("http://photos.example.net/photos")); 
      HttpParameters requestparameters = new HttpParameters(); 
      OAuthMessageSigner signer = new HmacSha1MessageSigner(); 

requestparameters.put(OAuth.OAUTH_CONSUMER_KEY, "dpf43f3p2l4k3l03");   
      requestparameters.put(OAuth.OAUTH_TOKEN, "nnch734d00sl2jdk"); 
      requestparameters.put(OAuth.OAUTH_NONCE, "kllo9940pd9333jh"); 
      requestparameters.put(OAuth.OAUTH_TIMESTAMP, "1191242096"); 
      requestparameters.put(OAuth.OAUTH_SIGNATURE_METHOD, "HMAC-SHA1"); 
      requestparameters.put(OAuth.OAUTH_VERSION, "1.0"); 
      requestparameters.put("size", "original"); 
      requestparameters.put("file", "vacation.jpg"); 
      String OAUTH_SIG = signer.sign(requestSig, requestparameters); 
      System.out.println(OAUTH_SIG); 
} 

///上面生成此簽名:rYexRY70p6aDDWw0ox0SwERRK2w =

///下面的代碼不會生成正確的簽名

requestparameters.put("oauth_consumer_secret", "kd94hf93k423kf44"); 
      requestparameters.put(OAuth.OAUTH_TOKEN_SECRET, "pfkkdhi9sl3r4s00"); 

回答

0
OAuthMessageSigner signer = new HmacSha1MessageSigner(); 
    signer.setConsumerSecret(consumerSecret); 
    signer.setTokenSecret(tokenSecret); 

現在就工作,並生成正確的簽名。

0

請包括客戶端的完整源代碼。您提供的值時,谷歌的OAuth測試環節服務於這個簽名 -

OAuth realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D" 

沒有你的客戶產生什麼簽名值?

+0

上面生成這個簽名:rYexRY70p6aDDWw0ox0SwERRK2w = – Fabii 2012-04-16 19:48:27

+0

沒有OAuth.OAUTH_CONSUMER_SECRET參數,我會如何添加它? – Fabii 2012-04-16 19:49:39

相關問題