I'm having a lot of trouble figuring out what's going on here. I'm not getting any error messages from Google's end, and when I check the API it says that the requests are going through, but the document is nowhere in my google drive. I am very green when it comes to using Google's API's, and am pretty sure I am making a dumb mistake but not sure what. I am I have a service account tied to the application, but there is no Oauth scope specified when looking at it. I am no longer getting a "invalid_scope: Invalid OAuth scope or ID token audience provided " error, but something is still wrong. If someone could tell me what I'm doing wrong here I would appreciate it.
import win32com.client
import os
import csv
from google.oauth2 import service_account
from googleapiclient.discovery import build
def convert_csv_to_google_sheet(csv_file_path, spreadsheet_title):
scopes = ['https://www.googleapis.com/auth/spreadsheets']
credentials = service_account.Credentials.from_service_account_file('service_account_creds.json', scopes=scopes)
service = build('sheets', 'v4', credentials=credentials)
spreadsheet = service.spreadsheets().create(body={'properties': {'title': spreadsheet_title}}).execute()
spreadsheet_id = spreadsheet['spreadsheetId']
with open(csv_file_path, 'r', newline='', encoding='utf-8') as csv_file:
csv_reader = csv.reader(csv_file)
csv_data = list(csv_reader)
service.spreadsheets().values().update(
spreadsheetId=spreadsheet_id,
range='Sheet1!A1',
valueInputOption='RAW',
body={'values': csv_data}
).execute()
print(f'CSV file "{csv_file_path}" has been successfully converted to a Google Sheet with title "{spreadsheet_title}".')
{
"type": "service_account",
"project_id": "xxxxxxxx",
"private_key_id": "xxxxxxxxxxxxxxxxxxxxxxxx",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCVk2yK3muK5vFa\nW/sbS2GSMzxYB7bU1VhG+kBydckkjIk6Kz6OAtX9BSxD8Apq6V3RMHTJ2ml7+tg7\nAQw+USvGJp0Kx2bhcwH5hamK4AXhuv6r6ce+BaR9AtqwHOi7+RweOmZYU2csi9oN\ng8xbnOTmK7L7osLof7h6QS73B617TK3YUMH47E5Mx2GU/y3+8nsOYMFP4Rxfoh+e\nGyooGtKFf6etphgRCSA9Hsa822bEWTZCHMaKJMHuX/9E2xkrF3D74WycsYCU1uTc\n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1jwg2ZjhHpR7XRYxm30/3v799Wfes+CXduY284IfxBFUdW9\n/OTlSCVCG461+CuumKM8MyWUfzvuGvMxuxwpTyKJ8QKBgQCHGX/tk8rgpcSEMynU\nXeo55chklHRuHtikNX1grDWWjqFE/2ykD900NJNX5NAJJmb/nKF2jwuxJlor6OVp\ntlxYDfdxoHVxMTKMZj23OsyU5YAYlusJCsXhhJujCZHvnsX6m6IB2PMhqUgXmZjR\nX3KhpTXR88E13F420jdFddAOKQ==\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "xxxxxxxxxxxxxxxxxxxxxxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxxxxx%40txxxxxxxxx.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}