Skip to content

Latest commit

 

History

History
120 lines (79 loc) · 4.16 KB

File metadata and controls

120 lines (79 loc) · 4.16 KB

Google Drive API Python Wrapper

This is a Python class that provides a convenient wrapper for interacting with the Google Drive API. It includes methods for uploading, downloading, deleting files, creating folders, and searching for files on Google Drive.

Getting Started

Prerequisites

To use this wrapper, you need a Google Drive access token. This token has a short expiration period, so this wrapper is best suited for temporary automation tasks.

Generating Access Token

  1. Go to the Google OAuth Playground. image

  2. On the left panel, select "Drive API v3." image

  3. In the "Select & authorize APIs" section, find "https://www.googleapis.com/auth/drive" and click on it.

  4. Click the "Authorize APIs" button. image

  5. Follow the prompts to log in and grant access. image

  6. Click the "Exchange authorization code for tokens" button.

image

  1. You will receive an access token. Copy this token for use with the GDrive class.

Installation

No installation is required. Simply include the GDrive class in your Python project.

Usage

  1. Initialization:

    gdrive = GDrive("<YOUR_ACCESS_TOKEN>")
  2. Upload a File:

    res = gdrive.upload_file("file_name.png", "/path/to/local/file.png")
    print(res.json())
  3. Search for a File:

    res = gdrive.search_file("file_name.png")
    print(res.json())
  4. Download a File:

    res, file_path = gdrive.download_file("<FILE_ID>", "/path/to/save/file.png")
    print(res, file_path)
  5. Delete a File:

    res = gdrive.delete_file("<FILE_ID>")
    print(res.json())
  6. Create a Folder:

    res = gdrive.create_folder("<FOLDER_NAME>")
    print(res.json())
  7. Delete a Folder:

    res = gdrive.delete_folder("<FOLDER_ID>")
    print(res)

Note

  • Make sure to replace placeholders like <YOUR_ACCESS_TOKEN>, <FILE_ID>, <FOLDER_NAME>, <FOLDER_ID> with your actual values.

  • The example usage assumes you have a file and folder with the specified names and IDs on your Google Drive.

  • This wrapper is designed for temporary automation tasks due to the short expiration period of the access token.

  • For Long time use refer here Dirve automation

Feel free to customize and integrate these methods into your project as needed.

Others


ragu.great-site.net  ·  GitHub @raguggg  ·  Instagram @ragu2k Medium @ragug