Skip to content

Credentials matching the Google Calendar API Python quickstart #22339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cwant opened this issue Apr 1, 2025 · 4 comments
Open

Credentials matching the Google Calendar API Python quickstart #22339

cwant opened this issue Apr 1, 2025 · 4 comments
Assignees

Comments

@cwant
Copy link

cwant commented Apr 1, 2025

Hi there,

I'm trying to rework a script from back in the OOB auth days.
I noticed that there is a python calendar quickstart that is very similar to the activities I'd like to perform.

https://developers.google.com/workspace/calendar/api/quickstart/python?hl=en

It works great out of the box using a JSON file with credentials for a "Desktop App".

Can I use this credentials JSON file with one of the auth classes that come with this Ruby library? If so, how?

Thanks,
Chris

@cwant
Copy link
Author

cwant commented Apr 3, 2025

@cwant
Copy link
Author

cwant commented Apr 3, 2025

Aw shoot, this points to 5 year old documentation using OOB.

Please don't tell me that this stuff works with Python but has been disabled for Ruby?

@cwant
Copy link
Author

cwant commented Apr 3, 2025

Actually the InstalledAppFlow example from the link above does work very much like the python example.

Sorry for the noise.

@cwant
Copy link
Author

cwant commented Apr 4, 2025

So this is a similar example to the python one (in this case, just listing from drive).

I hope it helps the next person (and I hope somebody might have suggestions in case of defects):

require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'google/api_client/auth/storages/file_store'
require 'google/api_client/auth/storage'

require 'google/apis/drive_v2'

TOKEN_FILE = 'token5.json'
SECRETS_FILE = 'client_secrets.json'

token_store = Google::APIClient::FileStore.new(TOKEN_FILE)
storage = Google::APIClient::Storage.new(token_store)
storage.authorize
authorization = storage.authorization

if (!authorization || authorization.expired?)
  client_secrets = Google::APIClient::ClientSecrets.load(SECRETS_FILE)
  flow = Google::APIClient::InstalledAppFlow.new(
    :client_id => client_secrets.client_id,
    :client_secret => client_secrets.client_secret,
    :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
    :port => 5000)

  authorization = flow.authorize(storage)
end

drive = Google::Apis::DriveV2::DriveService.new
drive.authorization = authorization
files = drive.list_files

files.items.each do |file|
  puts file.title
end

See the linked python tutorial above about how to get the client secrets file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy