使用iOS Facebook SDK有没有办法让facebook用户朋友过生日?此外,我试图从用户事件中加载用户朋友的生日,但我只收到了活动,而不是生日。
以下是我尝试过的代码:
class ViewController: UIViewController {
let facebookReadPermissions = ["user_events"]
override func viewDidLoad() {
super.viewDidLoad()
if FBSDKAccessToken.currentAccessToken() != nil {
return
}
FBSDKLoginManager().logInWithReadPermissions(self.facebookReadPermissions, handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if error != nil {
FBSDKLoginManager().logOut()
println(error)
} else if result.isCancelled {
FBSDKLoginManager().logOut()
println("cancelled")
} else {
var allPermsGranted = true
let perms = result.grantedPermissions as NSSet
let grantedPermissions = Array(result.grantedPermissions).map( {"\($0)"} )
for permission in self.facebookReadPermissions {
if !contains(grantedPermissions, permission) {
allPermsGranted = false
break
}
}
if allPermsGranted {
// Do work
println("all perm granted, success!")
let fbToken = result.token.tokenString
let fbUserID = result.token.userID
println(fbToken)
println(fbUserID)
self.getUserEvents()
} else {
println("failure")
}
}
})
}
func getUserEvents() {
if FBSDKAccessToken.currentAccessToken() != nil {
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "events"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if error == nil {
println(result)
println("----------------------")
println(result as! NSDictionary)
}
})
}
}
}
输出:
{
events = {
data = (
{
description = dfgfdgfdg;
id = 791086224356028;
name = "B party";
"rsvp_status" = attending;
"start_time" = "2015-08-30";
},
{
description = "\U0422\U0435\U0441\U0442";
id = 1624498701141585;
name = "\U0422\U0435\U0441\U0442";
place = {
id = 356733231072690;
location = {
city = Kirovohrad;
country = Ukraine;
latitude = "48.5046610418";
longitude = "32.2676611219";
zip = 250;
};
name = "\U0433. \U041a\U0438\U0440\U043e\U0432\U043e\U0433\U0440\U0430\U0434 , \U0423\U043a\U0440\U0430\U0438\U043d\U0430";
};
"rsvp_status" = attending;
"start_time" = "2015-08-30";
}
);
paging = {
cursors = {
after = TVRZAeU5EUTVPRGN3TVRFME1UVTROVG94TkRRd09URTRNREF3T2pFMk5UQTRORGc1TmpnME9EVTRNUT09;
before = TnpreE1EZAzJNakkwTXpVMk1ESTRPakUwTkRBNU1UZA3dNREE2TVRjMk9UQTRNVE0xTmpnM09UWXgZD;
};
};
};
id = 1569554686600399;
}
答案 0 :(得分:3)
从Facebook api v2.0起,所有好友权限都已被删除。你不能得到一个朋友的生日。参考https://developers.facebook.com/docs/apps/changelog