简体   繁体   English

Google云端存储iOS - 无需身份验证

[英]Google Cloud Storage iOS - Without Authentication

I'm trying to upload or download files from Google Cloud Storage without authentication. 我正在尝试从Google云端存储上传或下载文件而无需身份验证。 I tried to use something similar to this https://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Basics but didn't work. 我尝试使用类似于此https://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Basics的内容,但无效。

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)");
        })

When i tried the code above i get "Login Required" error, so i tried applying the following code before the code previous 当我尝试上面的代码时,我得到“需要登录”错误,所以我尝试在之前的代码之前应用以下代码

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

But doesn't work. 但是不起作用。 I get the error, keyName: "Request" 我收到错误,keyName: “请求”

Please give me an example how to make it works or what i'm doing wrong. 请举例说明如何使其工作或我做错了什么。

Thanks. 谢谢。

Although I'm not sure this will solve your problem; 虽然我不确定这会解决你的问题; all your variables are declared with the keyword let instead of var . 所有变量都使用关键字let而不是var来声明。 Using the let keyword prevents any future changes to the object. 使用let关键字可防止将来对对象进行任何更改。 It defines a constant. 它定义了一个常量。 This prevents you from changing the object's properties the way you are doing now. 这可以防止您以现在的方式更改对象的属性。 You can find more info about this in the Swift documentation . 您可以在Swift 文档中找到有关此内容的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM