繁体   English   中英

使用Ruby的Google文档API的OAuth问题(Rails 3.0.6)

[英]OAuth issues with Google Docs API using Ruby (Rails 3.0.6)

我们似乎无法根据Google Docs API创建新的电子表格。

我们的要求只是挂了。 我们在Rails 3.0.6上。

这是我们的代码:

 msg = '<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:category scheme="http://schemas.google.com/g/2005#kind"
                 term="http://schemas.google.com/docs/2007#document" />
  <atom:title>Company Perks</atom:title>
</atom:entry>'

oauth_base_string = 'POST&http://docs.google.com/feeds/documents/private/full&oauth_consumer_key=DOMAIN&oauth_nonce=1c4fbbe4387a685829d5938a3d97988c&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1227303732&oauth_version=1.0&xoauth_requestor_id=ID'  

key = 'KEY'

oauth_signature = CGI.escape(Base64.encode64("#{OpenSSL::HMAC.digest('sha1', key, oauth_base_string)}"))

headers = { 
  'Content-Type' => 'application/atom+xml',
  'Authorization' => 'OAuth oauth_consumer_key="DOMAIN",oauth_nonce"1c4fbbe4387a685829d5938a3d97988c",oauth_signature=' + oauth_signature + ',oauth_signature_method="HMAC-SHA1",oauth_timestamp="1227303732",oauth_version="1.0"'
}

uri = URI.parse 'http://docs.google.com/feeds/documents/private/full?xoauth_requestor_id=ID'
http = Net::HTTP.new uri.host, uri.port
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
resp, data = http.post(uri.request_uri, msg, headers)

传说:

DOMAIN = OAuth使用者密钥ID =我们要为其创建新电子表格的电子邮件地址KEY = OAuth使用者密钥

您是否有任何特殊原因要尝试手动编写它? 如果我猜到了,那是因为您的时间戳和随机数是硬编码的。 另外,IIRC Google使用Oauth 2.0并支持1.0a,因此您可能需要一个请求和访问令牌。 从您的示例中,我看不到您正在获取它。

IMO,您最好使用宝石。

Omniauth是一种非常受欢迎的宝石,它可以完全满足您的需求,并且包括Google oauth策略: https : //github.com/intridea/omniauth

另外,我过去曾经使用过这个gem,它对我的​​项目很有用。 http://oauth.rubyforge.org/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM