我已经创建了服务账户凭证,并在 AWS 实例上运行了我的代码。代码是:
from google.oauth2 import service_account
SCOPES = [ 'https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive' ]
SERVICE_ACCOUNT_FILE = 'serviceAccount.json'
APPLICATION_NAME = 'app name'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
drive_service = discovery.build('drive', 'v2', credentials=credentials)
settings = configparser.ConfigParser()
settings._interpolation = configparser.ExtendedInterpolation()
settings.read('caremarkets.ini')
origin_file_id = settings.get('GoogleSheetParams',''+manualType+'Manual2018')
folderId = settings.get('GoogleSheetParams',''+manualType+'FolderID')
timeStamp = '{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())
title = manualType+ " Userid: ( "+str(user_id)+" ) "+timeStamp
fileObject= drive_service.files().copy(
fileId=origin_file_id, body={"parents": [{"kind": "drive#fileLink",
"id": folderId}], 'title': title}).execute()
Run Code Online (Sandbox Code Playgroud)
但是这是我的错误:第 41 行是上面代码片段中的服务调用:
fileObject= drive_service.files().copy(
fileId=origin_file_id, body={"parents": [{"kind": "drive#fileLink",
"id": folderId}], 'title': title}).execute()
Run Code Online (Sandbox Code Playgroud)
File …Run Code Online (Sandbox Code Playgroud) oauth google-api google-drive-api service-accounts google-sheets-api