如何从Facebook注销或使用Parse和Swift撤消登录 [英] How to Log out from Facebook or revoke login using Parse and Swift
问题描述
我正在尝试将用户完全注销我的应用程序.使用时
PFUser.logout()
我成功地使用户退出了Parse. 但是,当我返回应用程序并单击登录"按钮时,我被重定向到Facebook屏幕,说:您已经授权了[应用程序名称]" 因此,除非重置模拟器,否则我再也无法使用其他帐户再次登录.
我也尝试使用登出
PFFacebookUtils.facebookLoginManager().logOut()
但是它也不起作用... 希望您能帮助我找到解决方案! 我正在使用最新的Facebook和Parse SDK
更新:
实际上使用PFUser.logout()
和 Parse 的最新版本以及 Facebook iOS SDK版本> = 4.4.0 即可.
请勿使用PFFacebookUtils.facebookLoginManager().logOut()
或FBSDKLoginManager().logOut()
,因为它只会使用户从 Facebook 注销,而不会从 Parse 后端注销.这意味着它将不会删除 Parse 后端上的可撤消会话.
实际上,撤消登录(让人们完全取消对应用的授权或撤消登录)和从用户的Facebook帐户注销:
撤销登录
(您可以查看 Facebook文档)>
您还可以通过调用此Graph API端点,让人们完全取消对应用程序的授权或撤消登录:
DELETE /{user-id}/permissions
必须使用有效的用户访问令牌或当前应用程序的应用程序访问令牌发出此请求.如果请求成功,则您的应用将收到true响应.如果呼叫成功,则该用户的任何用户访问令牌都将失效,并且他们将不得不再次登录.由于您正在取消对应用程序的授权,因此他们也必须像首次登录一样授予对您应用程序的访问权限.
let facebookRequest: FBSDKGraphRequest! = FBSDKGraphRequest(graphPath: "/me/permissions", parameters: nil, HTTPMethod: "DELETE")
facebookRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if(error == nil && result != nil){
println("Permission successfully revoked. This app will no longer post to Facebook on your behalf.")
println("result = \(result)")
} else {
if let error: NSError = error {
if let errorString = error.userInfo?["error"] as? String {
println("errorString variable equals: \(errorString)")
}
} else {
println("No value for error key")
}
}
}
从其Facebook帐户注销用户
如果您已使用 Parse 和 Facebook iOS SDK版本> = 4.4.0 来通过 Facebook 注册或登录用户,并且您不想取消对应用程序的授权或撤销登录,而只想从Facebook中注销用户,请改用:
PFUser.logOut()
它将注销用户,删除 Parse 后端的会话(请不要忘记可撤消会话(通过您的Parse应用设置)),此外,它还将删除写在用户设备磁盘上的 Facebook 会话.
我希望这个答案对您有所帮助.
I'm trying to completely log my user out of my app. When using
PFUser.logout()
I successfully log the user out of Parse. But when I come back in the app and click on the login button, I'm redirected to the Facebook screen saying :"You have already authorized [name of the app]" So I can never login again with another account, except if I reset the simulator.
I also tried to logout using
PFFacebookUtils.facebookLoginManager().logOut()
But it doesn't work either... Hope you can help me find a solution to this ! I'm using the latest Facebook and Parse SDK
Update:
Actually using PFUser.logout()
and the last versions of Parse and the Facebook iOS SDK version >= 4.4.0 will do the job.
Do not use PFFacebookUtils.facebookLoginManager().logOut()
or FBSDKLoginManager().logOut()
, because it will only log the user out from Facebook but not from the Parse back-end. Which means that it will not delete the revocable session on the Parse back-end.
Actually there is a difference between Revoking Login (letting people completely de-authorizing an app, or revoking login) and Logging out an user from his/her Facebook account:
Revoking Login
(you can check the Facebook documentation)
You can also let people completely de-authorize an app, or revoke login, by making a call to this Graph API endpoint:
DELETE /{user-id}/permissions
This request must be made with a valid user access token or an app access token for the current app. If the request is successful, your app receives a response of true. If the call is successful, any user access token for the person will be invalidated and they will have to log in again. Because you're de-authorizing your app, they will also have to grant access to your app as if they were logging in for the first time.
let facebookRequest: FBSDKGraphRequest! = FBSDKGraphRequest(graphPath: "/me/permissions", parameters: nil, HTTPMethod: "DELETE")
facebookRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if(error == nil && result != nil){
println("Permission successfully revoked. This app will no longer post to Facebook on your behalf.")
println("result = \(result)")
} else {
if let error: NSError = error {
if let errorString = error.userInfo?["error"] as? String {
println("errorString variable equals: \(errorString)")
}
} else {
println("No value for error key")
}
}
}
Logging out an user form his/her Facebook account
If you have used Parse and the Facebook iOS SDK version >= 4.4.0 to sign up or log in a user via Facebook, and you do not want to de-authorize an app, or revoke login, but just want to log out the user from Facebook, then please use instead:
PFUser.logOut()
It will log out the user, delete the session on the Parse back-end side (do not forget to enable Parse revocable session via your Parse app settings), plus it will also delete the Facebook session written on the user device's disk.
I hope this answer will help you guys.
这篇关于如何从Facebook注销或使用Parse和Swift撤消登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!