【发布时间】:2016-01-27 00:50:30
【问题描述】:
我在 Windows 10 上使用 python google drive api,python 2.7.10。
我正在为驱动服务设置一个实例变量。当我尝试运行驱动器服务的方法之一self.service.files().list() 时,就会出现问题。我相信python正在传递对象self和字符串"title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'"是否可以阻止python这样做?
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']
【问题讨论】:
标签: python google-drive-api typeerror