Reputation: 694
I am using python google drive api, python 2.7.10 on windows 10.
I am setting a instance variable to a drive service. The problem arises when I try to run one of the the drive's service's methods self.service.files().list()
. I believe that python is passing both the object self
and the string "title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'"
Is there away to stop python from doing this?
class doorDrive():
def __init__(self, scopes = 'https://www.googleapis.com/auth/drive.metadata.readonly',
secretFile = 'client_secret.json',
appName = 'Door Cam'):
self.SCOPES = scopes
self.CLIENT_SECRET_FILE = secretFile
self.APPLICATION_NAME = appName
self.photoFolderId = ''
creds = self.getCreds()
http = creds.authorize(httplib2.Http())
self.service = discovery.build('drive', 'v2', http=http)
self.initFolder()
def getCreds(self):
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'drive-python-quickstart.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(self.CLIENT_SECRET_FILE, self.SCOPES)
flow.user_agent = self.APPLICATION_NAME
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
def initFolder(self):
folders = self.service.files().list("title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'").execute()['items']
Upvotes: 0
Views: 699
Reputation: 32542
Your last line is passing your query string directly to list()
, but you should probably be passing it in by keyword, like this:
def initFolder(self):
folders = self.service.files().list(q="title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'").execute()['items']
Notice the q=
in the front of your query now. That will make Python send it in as a keyword argument instead of a positional argument. I think your error is cascading further downward because the first argument to that function is actually orderBy
.
You can see the specification here: https://developers.google.com/resources/api-libraries/documentation/drive/v2/python/latest/drive_v2.files.html#list
Upvotes: 2