Create a Drive File with a set locale in international settings through Drive API

Viewed 331

I need to create a file using the Google Drive API (I'm using v3, the latest at the moment). Using python if it matters.

My code is below,

drive_service.files().create(supportsTeamDrives=True, body={
                    'name': 'test-file',
                    'mimeType': 'application/vnd.google-apps.spreadsheet',
                    'parents': [folder_id],
                    'properties': {'locale': 'en_GB',
                                   'timeZone': 'Europe/Berlin'}
                })

Following the documentation @here, I tried to set the properties key with the locale set to the wanted one but it keeps creating the file with the default locale of my account.

How can I make it work at the creation time? is there another parameter I can fill?

2 Answers

Your problem is that you are mixing up two different "properties".

The properties you are setting are user-defined properties which are only ever consumed by you yourself. They are of no significance to Google.

The properties you want to set are part of the Spreadsheet API. See https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#SpreadsheetProperties

The simplest solution is to not use the Drive API to create your spreadsheet. Instead use the Spreadsheet API as descibed https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create

I just tested this in the Apis Explorer

Create file Request

POST https://www.googleapis.com/drive/v3/files?key={YOUR_API_KEY}

{
 "properties": {
  "test": "test"
 },
 "name": "Hello"
}

Response

{    

 "kind": "drive#file",
 "id": "1CYFI5rootSO5cndBD2gFb1n8SVvJ7_jo",
 "name": "Hello",
 "mimeType": "application/octet-stream"
}

File get request

GET https://www.googleapis.com/drive/v3/files/1CYFI5rootSO5cndBD2gFb1n8SVvJ7_jo?fields=*&key={YOUR_API_KEY}

Response

 "kind": "drive#file",
 "id": "1CYFI5rootSO5cndBD2gFb1n8SVvJ7_jo",
 "name": "Hello",
 "mimeType": "application/octet-stream",
 "starred": false,
 "trashed": false,
 "explicitlyTrashed": false,
 "parents": [
  "0AJpJkOVaKccEUk9PVA"
 ],
 "properties": {
  "test": "test"
 },

It appears to be working just fine i suggest you try checking the following:

  • The file id that is returned in the response from creating the file. To ensure that you are checking the one you just uploaded. Every time you run that you are going t create a new file.
  • Also remember to add fields=* with file.get if that's what you are using to check the result of your properties.
Related