如何在 facebooksdk v4.0.1 上更新 FBRequest.requestForMe()?
How to update FBRequest.requestForMe() on facebooksdk v4.0.1?
所以,我在 iphone 上申请了。我正在使用 facebook 登录,目前正在将我的 facebooksdk 升级到最新版本。我的一些代码碰巧有错误。下面是我的代码:
let request = FBRequest.requestForMe()
request.startWithCompletionHandler({ (connection, result, error) -> Void in
if error == nil {
if let userData = result as? NSDictionary {
let facebookId = userData["id"] as! String
self.user.name = userData["name"]as! String
// self._fbuser.location = userData["location"]["name"] as String
self.user.gender = userData["gender"] as! String
self.user.imgUrl = NSURL(string: NSString(format: "https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookId) as String)
self.user.isFacebookUser = true
}
} else {
if let userInfo = error.userInfo {
if let type: AnyObject = userInfo["error"] {
if let msg = type["type"] as? String {
if msg == "OAuthException" { // Since the request failed, we can check if it was due to an invalid session
println("The facebook session was invalidated")
self.onLogout("")
return
}
}
}
}
println("Some other error: \(error)")
}
})
那我该如何解决呢?什么代码等于或类似于 FBRequest.requestme ?
在 facebook sdk 中获取用户信息 4.x swift
@IBAction func btnFBLoginPressed(sender: AnyObject) {
var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager .logInWithReadPermissions(["email"], handler: { (result, error) -> Void in
if (error == nil){
var fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.containsObject("email"))
{
self.getFBUserData()
fbLoginManager.logOut()
}
}
})
}
func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
println(result)
}
})
}
}
输出:
{
email = "ashishkakkad8@gmail.com";
"first_name" = Ashish;
id = 910855688971343;
"last_name" = Kakkad;
name = "Ashish Kakkad";
picture = {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/10394859_900936369963275_5557870055628103117_n.jpg?oh=fefbfca1272966fc78286c36741f9ac6&oe=55C89225&__gda__=1438608579_9133f15e55b594f6ac2306d61fa6b6b3";
};
};
}
所以,我在 iphone 上申请了。我正在使用 facebook 登录,目前正在将我的 facebooksdk 升级到最新版本。我的一些代码碰巧有错误。下面是我的代码:
let request = FBRequest.requestForMe()
request.startWithCompletionHandler({ (connection, result, error) -> Void in
if error == nil {
if let userData = result as? NSDictionary {
let facebookId = userData["id"] as! String
self.user.name = userData["name"]as! String
// self._fbuser.location = userData["location"]["name"] as String
self.user.gender = userData["gender"] as! String
self.user.imgUrl = NSURL(string: NSString(format: "https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookId) as String)
self.user.isFacebookUser = true
}
} else {
if let userInfo = error.userInfo {
if let type: AnyObject = userInfo["error"] {
if let msg = type["type"] as? String {
if msg == "OAuthException" { // Since the request failed, we can check if it was due to an invalid session
println("The facebook session was invalidated")
self.onLogout("")
return
}
}
}
}
println("Some other error: \(error)")
}
})
那我该如何解决呢?什么代码等于或类似于 FBRequest.requestme ?
在 facebook sdk 中获取用户信息 4.x swift
@IBAction func btnFBLoginPressed(sender: AnyObject) {
var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager .logInWithReadPermissions(["email"], handler: { (result, error) -> Void in
if (error == nil){
var fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.containsObject("email"))
{
self.getFBUserData()
fbLoginManager.logOut()
}
}
})
}
func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
println(result)
}
})
}
}
输出:
{
email = "ashishkakkad8@gmail.com";
"first_name" = Ashish;
id = 910855688971343;
"last_name" = Kakkad;
name = "Ashish Kakkad";
picture = {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/10394859_900936369963275_5557870055628103117_n.jpg?oh=fefbfca1272966fc78286c36741f9ac6&oe=55C89225&__gda__=1438608579_9133f15e55b594f6ac2306d61fa6b6b3";
};
};
}