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

How to pass my auth_token and refresh tokens to

我在 rails 中使用 google-api-ruby-client gem。

在示例中,我找到了加载 GooglePlus 数据的示例:

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

我已经用另一种方法(使用devise oauth)获得了refresh_tokenauth_token

如何从我拥有的令牌开始生成 authorization 对象?

您可以像这样通过实例化一个新的 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')