ruby-on-rails-3 – 为Netflix生成oauth_signature

我正在尝试生成一个用于Netflix的oauth签名.我一直在关注他们的API文档,但是当他们到达“
If you are using a library, once you have created your base string, it is easy to generate the signature. You pass your base string and your shared secret to a function and get the signature back. See the OAuth Code Page for examples”的行时会遇到问题.

我可以创建我的基本字符串并拥有我的共享秘密,但无法弄清楚如何使用Oauth gem生成签名.

任何帮助都会很棒.

最佳答案 我最终手工创建Oauth签名而不是使用gem:

  plain_url = "#{NETFLIX_PUBLIC_URL}"+"#{NETFLIX_TOKEN_ACCESS}"


   latest_time = "#{Time.now.to_i}"
   nonce = rand(1_000_000)
   token_string="oauth_consumer_key=#{NETFLIX_KEY}&oauth_nonce=#{nonce}&oauth_signature_method=HMAC-SHA1&oauth_timestamp=#{latest_time}" +
       "&oauth_token=#{oauth_token}&oauth_version=1.0"

   encoded_string = CGI.escape(token_string)
   encoded_url = CGI.escape(plain_url)
   signature_string=  "GET&"+encoded_url+"&"+encoded_string
   puts "signature string is " + signature_string

   signature_key = "#{NETFLIX_SECRET}&#{token_secret}"

   signature = Base64.encode64(HMAC::SHA1.digest( signature_key,signature_string)).chomp.gsub(/\n/,'')

   encoded_signature = CGI.escape(signature)
   call = plain_url + "?" + token_string + "&oauth_signature="+encoded_signature
点赞