'Missing package dependencies in Google's Drive API - name 'drive_service' is not defined

I try to connect Python with the Google Drive following this introduction.

Unfortunately, the dependencies seem to be missing to execute the following code

file_metadata = {
    'name': 'Invoices',
    'mimeType': 'application/vnd.google-apps.folder'
}
file = drive_service.files().create(body=file_metadata,
                                    fields='id').execute()
print('Folder ID: %s' % file.get('id'))

Does anybody know, from where I need to import drive_service?



Solution 1:[1]

drive_service is not a module to import, but is an object you build with credentials and scopes using the google-api-python-client in this case. It is through that authorized drive_service that you can make calls to Drive API.

In the quickstart here: https://developers.google.com/drive/api/v3/quickstart/python you can see how to import the build function to create the service, as well as the pip command to install the client library.

So in your example you could build a Drive service with the following command. Do have a go at the quickstart guide referenced above.

drive_service = build('drive', 'v3', credentials=creds)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aerials