Swift 列表需要3个元素,但我不需要';我不知道第三个来自哪里
因此,我试图遵循OAuth2.0的教程。 在“OAuthSwift与嵌入式Web视图”部分下。 这就是整个功能:Swift 列表需要3个元素,但我不需要';我不知道第三个来自哪里,swift,oauth-2.0,Swift,Oauth 2.0,因此,我试图遵循OAuth2.0的教程。 在“OAuthSwift与嵌入式Web视图”部分下。 这就是整个功能: // 1 Create OAuth2Swift object let oauthswift = OAuth2Swift( consumerKey: "YOUR_GOOGLE_DRIVE_CLIENT_ID", // 2 Enter google app settings consumerSecret: "YOUR_GOOGLE_DRIVE_CLIENT_
// 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个参数,但指定的参数只有两个。任何帮助都将不胜感激。可能是这两个参数在教程制作(或上次更新)时是有效的,现在它需要三个参数。因此,替换:
success: { credential, response in
var parameters = [String: AnyObject]()
...
与:
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
}
因此,基本上我必须删除整行
var参数=[String:AnyObject]()
?并添加参数
作为第三个预期参数?当我这样做时,我在let jsonDict:AnyObject!=NSJSONSerialization.JSONObjectWithData(数据,选项:nil,错误:nil)
这是:“调用中的额外参数错误”。谢谢,但现在由于错误处理而出现了问题。我必须试着抓住它。。。
do {
let jsonDict = try NSJSONSerialization.JSONObjectWithData(data, options: []) as! [String: AnyObject]
// And replace [String: AnyObject] with your JSON format.
} catch {
// Error handling here
}