This Python script is designed to modify the sharing settings of all files within a specified Google Drive folder. Specifically, it turns off link sharing for each file, effectively setting each file's access to 'restricted'. This ensures that files are no longer accessible via shared links and can only be accessed by users who have been explicitly granted permission.
To use this script, you will need:
- Python installed on your system.
- Google Client Library for Python installed in your Python environment.
- OAuth 2.0 credentials set up in your Google Cloud project for the Google Drive API.
credentials.jsonfile downloaded from your Google Cloud project and placed in the same directory as the script.
- Open the script in a Python editor or IDE.
- Replace
'your_folder_id_here'in thefolder_idvariable with the actual ID of the Google Drive folder you wish to modify. - Run the script. It will authenticate via OAuth 2.0 and proceed to modify the sharing settings of all files within the specified folder.
- The script uses the Google Drive API to access and modify file permissions.
- It processes files in batches of 100 due to API pagination and continues until all files in the folder have been processed.
- Link sharing permissions are removed from each file, and access is set to restricted.
- The script provides console output for each file it processes, indicating the completion of the operation or any errors encountered.
- Ensure that you have the necessary permissions to modify the files in the specified folder.
- The script requires internet access to interact with the Google Drive API.
- Handle the OAuth 2.0 credentials and
credentials.jsonfile securely.
StreamBit https://github.com/StreamBit