使用 HTTParty 在 ruby 中获得 google drive api 调用的授权

Get authorization for google drive api calls in ruby with HTTParty

我想要获得授权访问权限,以便 google 驱动器 api 调用。

我使用 ruby,和 HTTParty gem。

我遵循了这个快速入门示例:https://developers.google.com/drive/v3/web/quickstart/ruby

然后,我想使用 HTTParty 来使用这个 API,我知道我必须获得使用上述凭据获得的用户 access_token 的授权,但是当我尝试这个时代码 HTTParty.get('https://www.googleapis.com/drive/v3/about', headers: {'Authorization' => "Bearer #{service.authorization.access_token}"})

我得到了这个错误状态: ...."code"=>400, "message"=>"The 'fields' parameter is required for this method."}}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>,....

我的目标是对 Google 驱动器 API 的用法进行一些测试。

我应该如何获得此 API 的授权访问权限?

我找到了问题的答案!

我的错误不在授权上,而是在我忘记的字段请求参数上!

例如

HTTParty.get('https://www.googleapis.com/drive/v3/about?fields=kind,user', headers: {'Authorization' => "Bearer #{service.authorization.access_token}"})

感谢此文档:

https://developers.google.com/drive/v3/web/performance?authuser=0#partial

再见!