简体   繁体   English

如何将我的auth_token和刷新令牌传递给

[英]How to pass my auth_token and refresh tokens to

I'm using the google-api-ruby-client gem in rails. 我在rails中使用google-api-ruby-client gem。

In the examples I found an example to load GooglePlus data: 在示例中,我找到了一个加载GooglePlus数据的示例:

client = Google::Apis::PlusV1::PlusService.new
client.key = ENV['GOOGLE_CLIENT_ID']
client.authorization = authorization

I have already obtained both refresh_token and the auth_token with another method (using devise oauth). 我已经通过另一种方法 (使用auth_token oauth) 获得了refresh_tokenauth_token

How can I generate the authorization object, starting from the tokens I have? 如何从拥有的令牌开始生成authorization对象?

You can create the authorization object by instantiate a new UserRefreshCredentials like this: 您可以通过实例化新的UserRefreshCredentials来创建授权对象,如下所示:

 authorization = Google::Auth::UserRefreshCredentials.new(
      client_id: GOOGLE_CLIENT_ID
      client_secret: GOOGLE_CLIENT_SECRET
      scope: GOOGLE_SCOPE,
      access_token: YOUR_AUTH_TOKEN,
      refresh_token: YOUR_REFRESH_TOKEN,
      expires_at: YOUR_EXPIRE_AT_TIMESTAMP,
      grant_type: 'authorization_code')

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

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