I created Service Account Credentials
here and got json key service.json
.
Then I tried:
from google.oauth2 import service_accou
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
https://www.googleapis.com/auth/drive
?When your script is modified, please modify it as follows.
from googleapiclient.discovery import build # Added
from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/drive'] # Modified
credentials = service_account.Credentials.from_service_account_file('service.json', scopes=SCOPES)
drive = build('drive', 'v3', credentials=credentials)
file_metadata = {
'name': 'sampleName',
'parents': ['#### folderId ###'],
'mimeType': 'application/vnd.google-apps.spreadsheet',
}
res = drive.files().create(body=file_metadata).execute()
print(res)
#### folderId ###
, please set the folder ID shared with the email of the service account.SCOPES = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]
.If I misunderstood your question and this was not the direction you want, I apologize.