Sol*_*ola 5 objective-c ios instagram parse-platform swift
如何创建在解析中对用户进行身份验证所需的会话令牌。我已经能够关注这篇博客文章http://blog.parse.com/announcements/bring-your-own-login/,但我不知道如何使用 Swift(IOS) 生成会话令牌。
这就是我到目前为止所拥有的。
func doAuthInstagram() {
let oauthswift = OAuth2Swift(
consumerKey: Instagram["consumerKey"]!,
consumerSecret: Instagram["consumerSecret"]!,
authorizeUrl: "https://api.instagram.com/oauth/authorize",
responseType: "token"
)
let state: String = generateStateWithLength(20) as String
oauthswift.authorize_url_handler = WebViewController()
oauthswift.authorizeWithCallbackURL(NSURL(string: "oauth-swift://oauth-callback/instagram")!, scope: "likes+comments", state: state,
success: { (credential, response, parameters) -> Void in
let url: String = "https://api.instagram.com/v1/users/self/?access_token=\(credential.oauth_token)"
let parameters: Dictionary = Dictionary<String, AnyObject>()
oauthswift.client.get(url, parameters: parameters,
success: { (data, response) -> Void in
let jsonDict: AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
let user = PFUser()
if let userData: AnyObject = jsonDict["data"] {
let name: String = userData["full_name"] as! String
let username: String = userData["username"] as! String
let id: String = userData["id"] as! String
let profileImage: String = userData["profile_picture"] as! String
user.username = username
user.password = id
user["name"] = name
user["profileImage"] = profileImage
user.signUpInBackgroundWithBlock { (success, error) -> Void in
if (success) {
println("user: \(user)")
PFUser.logInWithUsernameInBackground(username, password: id, block: { (user, error) -> Void in
if user != nil {
self.performSegueWithIdentifier("loginSegue", sender: self)
} else {
ProgressHUD.showError("\(error)")
}
})
} else if let error = error!.userInfo!["error"] as? NSString {
if error == "username \(username) already taken" {
PFUser.logInWithUsernameInBackground(username, password: id, block: { (user, error) -> Void in
if user != nil {
self.performSegueWithIdentifier("loginSegue", sender: self)
} else {
ProgressHUD.showError("\(error)")
}
})
} else {
ProgressHUD.showError("\(error)")
}
}
}
}
}, failure: { (error) -> Void in
ProgressHUD.showError("\(error)")
})
}) { (error) -> Void in
println(error.localizedDescription)
ProgressHUD.showError("\(error.localizedDescription)")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
624 次 |
| 最近记录: |