3
我試圖從谷歌雲存儲上傳或下載文件,而無需身份驗證。我試圖使用類似於這個https://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Basics但沒有工作。谷歌雲存儲iOS - 無需身份驗證
let storage = GTLServiceStorage()
storage.additionalHTTPHeaders = ["x-goog-project-id":"my-project-id", "Content-Type": "application/json-rpc", "Accept": "application/json-rpc"]
storage.APIKey = "my-server-api-key"
storage.retryEnabled = true
// bucket
let bucket : GTLStorageBucket = GTLStorageBucket()
bucket.name = "my-bucket-name"
// this code doesn't matter is only for test the previous code
let query : GTLQueryStorage = GTLQueryStorage.queryForBucketsInsertWithObject(bucket, project: "my-project-id") as GTLQueryStorage
self.storage.executeQuery(query, completionHandler: { (ticket : GTLServiceTicket!, object : AnyObject!, error : NSError!) -> Void in
NSLog("Bucket: \(object)");
})
當我嘗試上面的代碼,我得到「需要登錄」錯誤,所以我嘗試代碼前面
auth.scope = kGTLAuthScopeStorageDevstorageFullControl
auth.clientID = "ios-client-id"
auth.clientSecret = "ios-client-secret"
auth.redirectURI = "urn:ietf:wg:oauth:2.0:oob"
storage.authorizer = auth // then set authorization to StorageService
之前將下面的代碼,但不起作用。我得到的錯誤,keyName:「請求」
請給我一個例子如何使它的工作原理或我做錯了什麼。
謝謝。
有沒有這方面的運氣?我仍然試圖找到一個iOS上傳的無縫方式,但它接縫不可能! – 2015-07-30 18:54:24
請檢查這個答案[鏈接](http://stackoverflow.com/a/32442387/1767847) – Ivan 2015-09-07 16:02:26