Title: Google Drive Python API: Adding Multiple Properties · Issue #947 · googleapis/google-api-python-client · GitHub
Open Graph Title: Google Drive Python API: Adding Multiple Properties · Issue #947 · googleapis/google-api-python-client
X Title: Google Drive Python API: Adding Multiple Properties · Issue #947 · googleapis/google-api-python-client
Description: Hello, I would like to add multiple entries into the properties metadata field for a file so that the file is indexable using files().list(). Here is my code: # define read and write permissions SCOPES = ['https://www.googleapis.com/auth...
Open Graph Description: Hello, I would like to add multiple entries into the properties metadata field for a file so that the file is indexable using files().list(). Here is my code: # define read and write permissions SC...
X Description: Hello, I would like to add multiple entries into the properties metadata field for a file so that the file is indexable using files().list(). Here is my code: # define read and write permissions SC...
Opengraph URL: https://github.com/googleapis/google-api-python-client/issues/947
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Google Drive Python API: Adding Multiple Properties","articleBody":"Hello,\r\n\r\nI would like to add multiple entries into the `properties` metadata field for a file so that the file is indexable using `files().list()`. Here is my code:\r\n```py\r\n# define read and write permissions\r\n\r\nSCOPES = ['https://www.googleapis.com/auth/drive.file']\r\n\r\n# check if the user's access and refresh tokens already exist\r\n\r\nimport pickle\r\nimport os\r\n\r\nif os.path.exists('token.pickle'):\r\n with open('token.pickle','rb') as f:\r\n creds = pickle.load(f)\r\nelse:\r\n creds = None\r\n\r\n\"\"\"\r\nIf the user's access and refresh tokens don't exist, or they are no longer valid, then create them and save them. This will not work if the credentials.json file is not in the user's working directory.\r\n\"\"\"\r\n\r\nfrom google_auth_oauthlib.flow import InstalledAppFlow\r\nfrom google.auth.transport.requests import Request\r\n\r\nif not creds or not creds.valid:\r\n if creds and creds.expired and creds.refresh_token:\r\n creds.refresh(Request())\r\n else:\r\n flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)\r\n creds = flow.run_local_server(port=0)\r\n \r\n with open('token.pickle', 'wb') as f:\r\n pickle.dump(creds,f)\r\n\r\n\"\"\"\r\ncheck that the authentication flow worked. This should be the same as the string in the \"client_id\" field in the credentials.json file. Additionally, if the access and refresh tokens did not already exist, then a token.pickle file should now be in the user's working directory.\r\n\"\"\"\r\n\r\nprint('client_id is: {}'.format(creds.client_id))\r\n\r\n# create a drive object to directly interface with the user's Google Drive.\r\n\r\nfrom googleapiclient.discovery import build\r\n\r\ndrive = build('drive', 'v3',credentials=creds)\r\n\r\n# create a folder in the root directory of the user's Google Drive.\r\n\r\nfolder_metadata = {\r\n \r\n 'name': 'TestFolder',\r\n 'mimeType': 'application/vnd.google-apps.folder'\r\n \r\n}\r\n\r\nfolder = drive.files().create(body = folder_metadata, fields = 'id,name').execute()\r\n\r\n# upload a file with indexable properties to the created folder\r\n\r\n# first create the file\r\nwith open('HelloWorld.txt','w') as f:\r\n f.write('Hello World!')\r\n\r\n# then define metadata\r\nproperty1 = {'key' : 'day_of_week', 'value' : 'Monday'}\r\nproperty2 = {'key' : 'patient_num', 'value' : '001'}\r\n\r\nfile_metadata = {\r\n 'name': 'HelloWorld.txt',\r\n 'parents': [folder['id']],\r\n 'properties':[property1,property2]\r\n}\r\n\r\n# finally upload\r\nfrom googleapiclient.http import MediaFileUpload\r\n\r\nmedia = MediaFileUpload('HelloWorld.txt',chunksize = -1,resumable = False)\r\nfile = drive.files().create(body = file_metadata, media_body = media, fields = 'name,properties').execute()\r\n\r\n# try to search for the file\r\n\r\nquery = \"properties has {key = 'patient_num' and value = '001'}\"\r\n\r\nfiles_list = drive.files().list(q = query, fields = 'files(name,properties)').execute()\r\n\r\n```\r\nWhen I execute this code, `files_list` contains `{'files': []}`. The reason for this is because the `file` variable contains:\r\n```\r\n{'name': 'HelloWorld.txt',\r\n 'properties': {'value': 'Monday', 'key': 'day_of_week'}}\r\n```\r\nClearly, the `'patient_num'` property was not added to the `properties` field, even though it was explicitly defined in the `file_metadata` dictionary. I am aware of this [question](https://stackoverflow.com/questions/19038308/google-drive-file-properties-how-to-set-multiple-properties-in-one-request) on Stack Overflow, but I feel that the proposed solution is inefficient. How do I add multiple properties to a file so that it is indexable using either the `day_of_week` property or the `patient_num` property or both properties at the same time? Also, once I can do this, how should I modify `query` so that I am able to index using multiple properties simultaneously?\r\n\r\nThanks a lot,\r\nMahmoud Abdelkhalek\r\n\r\n","author":{"url":"https://github.com/mhdadk","@type":"Person","name":"mhdadk"},"datePublished":"2020-06-24T16:21:51Z","url":"https://github.com/googleapis/google-api-python-client/issues/947"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7da6a7ea-dec5-6b9f-bd6a-508dd61af09a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C7E:35EBD3:1B78D:21175:6B088768 |
| html-safe-nonce | 27b491025c44cb463cb327f2acaa7b8302fb2a60b70702985eeee532a643c428 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzdFOjM1RUJEMzoxQjc4RDoyMTE3NTo2QjA4ODc2OCIsInZpc2l0b3JfaWQiOiIzNjUzOTIwMjQ0NjM0MjU3MjU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 367cde4555a89307f99d0e1bf87dc22b3bbec5e9d6208c5df57ec3d9227944d2 |
| hovercard-subject-tag | issue:644745243 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-api-python-client/947/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d7fb28b95c73a307323160460137fc0eac40b1c0624cda5711187cff5d712d5a/googleapis/google-api-python-client/issues/947 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d7fb28b95c73a307323160460137fc0eac40b1c0624cda5711187cff5d712d5a/googleapis/google-api-python-client/issues/947 |
| og:image:alt | Hello, I would like to add multiple entries into the properties metadata field for a file so that the file is indexable using files().list(). Here is my code: # define read and write permissions SC... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mhdadk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60e86161f3e246339ce8d4bd308e3da0ecd5ebd5e610d57e00d21487fe085d68 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-api-python-client git https://github.com/googleapis/google-api-python-client.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 15749269 |
| octolytics-dimension-repository_nwo | googleapis/google-api-python-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 15749269 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-api-python-client |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e87e2b0f8aff9e45b7ac6c81be5a939ad971830c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width