0
所以我試圖從here跟隨oAuth 2.0的教程。 在「帶有嵌入式Web視圖的OAuthSwift」部分下。 這是整個功能:列表期望3個元素,但我不知道第三個來自哪裏
// 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個參數,但指定只是兩個。任何幫助將非常感激。
所以,基本上我必須刪除整行'var parameters = [String:AnyObject]()'?並添加'參數'作爲第三個預期的參數?當我這樣做時,我在'let jsonDict:AnyObject! = NSJSONSerialization.JSONObjectWithData(data,options:nil,error:nil)'which is:「Extra argument error in call」。 – Walker
是的,並看到我更新的答案。 – xoudini
謝謝,但現在有錯誤處理的問題。我必須嘗試並抓住... – Walker