0
我終於設法使用Swift讓Google Drive API與iOS一起工作。將文件上傳到Google Drive與iOS的問題
我可以訪問我的Google雲端硬盤,並下載文件夾和文件名,所以我知道基本認證和API正在工作。
問題是,當我嘗試上傳一個小文件 - 並生成該錯誤
reason: 'unexpected response data (uploading to the wrong URL?)
{"error":{"code":403,"message":"Insufficient Permission","data":[{"domain":"global","reason":"insufficientPermissions","message":"Insufficient Permission"}]},"id":"gtl_7"}'
我已經設置了什麼看起來像一個有效的OAuth 2.0客戶端ID,但是當我第一次嘗試這樣做我有設置了錯誤的授權範圍(從我複製的示例中) - 'kGTLAuthScopeDriveReadonly'。我現在已將其更改爲'kGTLAuthScopeDrive',但我擔心應用程序可能仍在使用原始範圍,因爲我無法強制進行新的登錄。
下面是我使用的檢查,我登錄
func checkAuthorisation()
{
if let auth = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(
kKeychainItemName,
clientID: kClientID,
clientSecret: kClientSecret)
{
service.authorizer = auth
}
else
{
presentViewController(
createAuthController(),
animated: true,
completion: nil
)
}
}
和這裏的代碼是我上傳的代碼
let metaData = GTLDriveFile()
metaData.title = "testfile.DAT"
let dataGoogleDrive = strMessage.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
let uploadParamaters = GTLUploadParameters(data: dataGoogleDrive!, MIMEType: "text/plain")
let query = GTLQueryDrive.queryForFilesInsertWithObject(metaData, uploadParameters: uploadParamaters)
let serviceTicket = dataModel.googleDrive.service.executeQuery(query, completionHandler:
{(ticket, file, error) -> Void in
print("complete")
})
我發現了很多描述越來越困難職位Google Drive API已設置,但這不再是問題。
- 問題簡單地說,我仍然使用緩存的憑據與錯誤的範圍?如果是這樣,我該如何沖洗?
- 我需要在Google Developer Console中配置什麼東西?可以選擇將Drive API配置爲「允許用戶使用此應用程序創建新文檔」。但是當我嘗試使用它時,它不會允許我保存更改。
。 – Russell