Trouble with Google Apps API and Service Accounts in Ruby
This looks to me like you are using an older example. I think that's how you used to do it about a year ago. Back in late 2012 that method of setting up the app was deprecated because Signet was updated to handle all aspects of the OAuth2 setup.
Here is the code I generally use to create a service account. You can tweak it to fit into your method.
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => "https://www.googleapis.com/auth/drive",
:issuer => "<service account email>@developer.gserviceaccount.com",
:signing_key => Google::APIClient::KeyUtils.load_from_pkcs12("<private key file>-privatekey.p12", "notasecret"),
:person => "<users email address>")
client.authorization.fetch_access_token!
If you are still having issues let me know and I'll see if I can help.
How to set the Google API user to impersonate using a Service Account (Ruby Client)?
Here's the summary.
Do not use the OAuth2 gem from intridea if you are only trying to authenticate with Google. Rely on the signet Gem.
If you use a service account, you can specify a :person element and it will work so you impersonate that user and work on their behalf.
When you test your integration you must do so against the domain in which your project is hosted. You cannot test in a third-party domain until you've published your app!
Related Topics
Why Does Date.Yesterday Counts as Date.Today Also
Ruby Convert Single Quotes to Double Quotes in Xml
Ruby Enterprise Edition VS Ruby 1.9
Rails S Return: [Bug] Segmentation Fault
Remove All Data from Active Storage
Rails Activerecord Create or Find
Encoding Issues in JavaScript Files Using Rails Asset Pipeline
Yaml::Load Raises Undefined Class/Module Error
How to Raise an Exception in an Rspec Test
Ruby Equivalent for Python's For/Else
Ruby - Compare Two Enumerators Elegantly
How to Stub Out Warden/Devise with Rspec in Capybara Test
Devise Omniauthable Breaks Omniauth Authentication with 'Could Not Find a Valid Mapping for Path'
Why Does Hash#Select and Hash#Reject Pass a Key to a Unary Block
Can't Install Ruby via Rvm, Error Running '_Rvm_Make -J4' on Ubuntu 22.04
How to Figure Out Which Step I'Ve Just Executed in Cucumber's Afterstep Hook