[英]OAuth issues with Google Docs API using Ruby (Rails 3.0.6)
We can't seem to create a new spreadsheet per the Google Docs API. 我们似乎无法根据Google Docs API创建新的电子表格。
Our request merely hangs. 我们的要求只是挂了。 We're on Rails 3.0.6. 我们在Rails 3.0.6上。
Here's our code: 这是我们的代码:
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)
Legend: 传说:
DOMAIN = OAuth consumer key ID = the email address for whom we're trying to create a new spreadsheet KEY = OAuth consumer secret DOMAIN = OAuth使用者密钥ID =我们要为其创建新电子表格的电子邮件地址KEY = OAuth使用者密钥
Is there any particular reason you're trying to write it manually? 您是否有任何特殊原因要尝试手动编写它? If I were to guess, it'd be because your timestamp and nonce are hardcoded. 如果我猜到了,那是因为您的时间戳和随机数是硬编码的。 Also, IIRC Google uses Oauth 2.0 and supports 1.0a, so you'll likely need a request and access token. 另外,IIRC Google使用Oauth 2.0并支持1.0a,因此您可能需要一个请求和访问令牌。 From you example, I don't see that you are fetching it. 从您的示例中,我看不到您正在获取它。
IMO, You're likely better off using a gem. IMO,您最好使用宝石。
Omniauth is a fairly popular gem that does exactly what you need, and included the Google oauth strategy: https://github.com/intridea/omniauth Omniauth是一种非常受欢迎的宝石,它可以完全满足您的需求,并且包括Google oauth策略: https : //github.com/intridea/omniauth
Also, I've used this gem in the past, and it was useful for my project. 另外,我过去曾经使用过这个gem,它对我的项目很有用。 http://oauth.rubyforge.org/ http://oauth.rubyforge.org/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.