2016-01-26 90 views
0

我使用蟒谷歌驅動API,在Windows 10類型錯誤:()的方法恰恰1參數(2給出)

我一個實例變量設置到一個驅動器服務蟒2.7.10。當我嘗試運行驅動器的服務方法self.service.files().list()時出現問題。我相信蟒蛇通過對象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'] 

回答

2

你的最後一行是直接通過你的查詢字符串list(),但你可能應該通過關鍵字傳遞,就像這樣:

def initFolder(self): 
    folders = self.service.files().list(q="title = 'Door_Photos' and mimeType = 'application/vnd.google-apps.folder'").execute()['items'] 

請注意,在查詢前面的q=現在。這將使Python發送它作爲關鍵字參數,而不是位置參數。我認爲你的錯誤是進一步下降,因爲該函數的第一個參數實際上是orderBy

您可以在這裏看到詳細的說明:https://developers.google.com/resources/api-libraries/documentation/drive/v2/python/latest/drive_v2.files.html#list

相關問題