Package: gdnan
gdnanA Google Drive API wrapper written in python by@viperadnanwith ♥️.Project's BaseThe base of the project taken from lzzy12's repo python-aria-mirror-bot and modified, improved and compiled in a pip package.InstallingInstall using pippip3installgdnanUsage# Importing ModulesfromgdnanimportGoogleDrive,Auth,extractId,create_link# Client ID & Secret Obtained from Google Developer ConsoleGooogleDriveClientID="9999199991-128shwbnwinpcqv6hn7b29wuww4gmji.apps.googleusercontent.com"GooogleDriveClientSecret="2lhkFmsQ0W7wJaua72HwodjZ"# The below method is only for one time, you cam use saved# credentials for later use.# Call the Auth moduleauth=Auth(GooogleDriveClientID,GooogleDriveClientSecret)# Get the Authorization URLprint("Open this url in browser and enter the received code")print(auth.get_url())received_code=input("Enter received code: ")# Exchange received code and get credentials# You can store the credentials wherever you wantcredentials=auth.exchange_code(received_code)# Or save it in token.pickle or any other file#optionalauth.exchange_code(received_code,"token.pickle")# Now after generating .pickle or credentials you need to use only below steps# Authorized via credentialsgd=GoogleDrive(credentials)# Or You can Authorize via .pickle file too# and can set the working directory, like for share drive.workdir_id=extractId("https://drive.google.com/folderview?id=1Aricl6VpSiMmgFkgUSeTXiQh7WYxW6np")#optionalgd=GoogleDrive("token.pickle",workdir_id)# Upload file from local storageuploaded_file=gd.upload("path/to/file/or/folder/example.txt")# Upload file to custom folder using folder's id               #Optionaluploaded_file=gd.upload("path/to/file/or/folder/example.txt","root")print(uploaded_file.name)>>example.txt# To get Google Drive urlprint(uploaded_file.url)>>https://drive.google.com/uc?id=10xN4KBjKJXUwIHUv1R5rihbthYuENMUB&export=download# Alternate wayprint(create_link(uploaded_file.id,uploaded_file.mimeType))>>https://drive.google.com/uc?id=10xN4KBjKJXUwIHUv1R5rihbthYuENMUB&export=download# To create a folder named "Hello World !"#                           # Name       # Parent IDfolder=gd.create_folder("Hello World!",workdir_id)print(folder.name)>>HelloWorld!# Clone/Copy file or folder, you can specify custom folder id by "folder" parametercloned_file=gd.clone(uploaded_file.id)print(cloned_file.name)>>example.txt# Move file from one folder to anothergd.move(cloned_file.id,folder.id)# Make files public or set permission for the file to publically viewablegd.make_public(cloned_file.id)# Search for the file       #optional    #optionalfiles,next_page_token=gd.search(uploaded_file.name,limit=2,folder=workdir_id)forfileinfiles:print(file.name)>>example.txt# Move file to trashgd.delete(uploaded_file.id)# Delete file permanentlygd.delete(folder.id,True)# Empty Trash of the users accountgd.emptyTrash()Using Service AccountsIf you want to use service accounts than put a copy of all of your service accounts in a folder and use code belowfromgdnanimportGoogleDrivegd=GoogleDrive("path/to/service/account/folder",workdir_id)this will automatically rename your service accounts to0.json 1.json 2.json...(if not renamed) and automatically switch between service accounts if daily quota exceeded.TestingTest code by runningtest.pyin your terminal withpython3 test.py, don't forget to change the GooogleDriveClientID and GooogleDriveClientSecret.Copyright & LicenseCopyright © 2021 —Adnan AhmadLicensed under the terms of theGNU General Public License Version 3 ‐ 29 June 2007