Last active
December 7, 2021 10:42
-
-
Save massens/1a752099aedc2d8c91d98da5b6c56f9a to your computer and use it in GitHub Desktop.
Drive's Ruby API - Things I've learned using the googl-api-ruby-client 0.9 -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Authentification | |
#Notice the authorization.refresh!. | |
def get_drive_service(user) | |
authorization = Signet::OAuth2::Client.new( | |
:client_id => 'example', | |
:client_secret => 'example', | |
access_token: user.access_token, | |
refresh_token: user.refresh_token, | |
token_credential_uri: 'https://www.googleapis.com/oauth2/v3/token') | |
drive_service = Google::Apis::DriveV3::DriveService.new | |
authorization.refresh! | |
drive_service.authorization = authorization | |
return drive_service | |
end | |
#Deleting a file | |
#Moving a file to the trash, passing only one parameter | |
file_metadata = {trashed: true} | |
new_file = drive_service.update_file(file.gdrive_id,file_metadata,{}) | |
#Creating a notification channel | |
drive_service = get_drive_service(user) | |
page_token = user_get_drive_changes_page_token(user); | |
uuid = SecureRandom.uuid | |
channel = Google::Apis::DriveV3::Channel.new(id: uuid, type:'web_hook', address:'https://example.com/notifications') | |
result = drive_service.watch_change(page_token,channel) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this - Google picked it up and it would have taken me a long time to figure out how to watch_change without it.