因此,我试图遵循here的oAuth 2.0教程。
在“带有嵌入式Web视图的OAuthSwift”部分下。
这是整个功能:
// 1 Create OAuth2Swift object
let oauthswift = OAuth2Swift(
consumerKey: "YOUR_GOOGLE_DRIVE_CLIENT_ID", // 2 Enter google app settings
consumerSecret: "YOUR_GOOGLE_DRIVE_CLIENT_SECRET",
authorizeUrl: "https://accounts.google.com/o/oauth2/auth",
accessTokenUrl: "https://accounts.google.com/o/oauth2/token",
responseType: "code"
)
// 3 Trigger OAuth2 dance
oauthswift.authorizeWithCallbackURL(
NSURL(string: "com.raywenderlich.Incognito:/oauth2Callback")!,
scope: "https://www.googleapis.com/auth/drive", // 4 Scope
state: "",
success: { credential, response in
var parameters = [String: AnyObject]()
// 5 Get the embedded http layer and upload
oauthswift.client.postImage(
"https://www.googleapis.com/upload/drive/v2/files",
parameters: parameters,
image: self.snapshot(),
success: { data, response in
let jsonDict: AnyObject! = NSJSONSerialization.JSONObjectWithData(data,
options: nil,
error: nil)
self.presentAlert("Success", message: "Successfully uploaded!")
}, failure: {(error:NSError!) -> Void in
self.presentAlert("Error", message: error!.localizedDescription)
})
}, failure: {(error:NSError!) -> Void in
self.presentAlert("Error", message: error!.localizedDescription)
})
我在填充列表的第4点(范围)上遇到错误:
success: { credential, response in
var parameters = [String: AnyObject]()
它说它期望3个参数,但指定的只是2个。任何帮助将非常感激。
最佳答案
这两个参数可能是在制作教程(或最后更新)时有效的,现在它需要三个参数。因此,请替换:
success: { credential, response in
var parameters = [String: AnyObject]()
...
与:
success: { credential, response, parameters in
...
let jsonDict
行也采用旧格式,并且不处理错误,因此请将其更改为:do {
let jsonDict = try NSJSONSerialization.JSONObjectWithData(data, options: []) as! [String: AnyObject]
// And replace [String: AnyObject] with your JSON format.
} catch {
// Error handling here
}
关于swift - 列表中包含3个元素,但我不知道第三个元素来自何处,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35259955/