iOS以快速,最新的FBSDK为用户的家乡 [英] iOS get user's hometown with swift and latest FBSDK
问题描述
我找不到适用于Facebook SDK的快速文档。我正在使用最新版本,我设法检索用户的姓名,年龄,邮件和个人资料图片。我不知道如何找到家乡。
I couldn't find a swift doc for Facebook SDK. I'm using the latest version and I managed to retrieve name, age, mail and profile picture of the user. I can't find out how to find the hometown though.
当我尝试这个:
conn.addRequest(req, completionHandler: { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if(error != nil){
println(error)
} else {
let loc = result.objectForKey("hometown") // loc is nil
}
})
conn.start()
我发现没有。我知道.objectForKey(hometown)应该返回一个Page而不是一个String,但是我不知道如何处理页面。
I found nil. I know that ".objectForKey("hometown")" should return a "Page" and not a "String" but I don't know how to handle a page.
Cheers
编辑:(感谢Tobi)
我需要添加 user_location
在登录权限然后,找到位置,我使用:
EDIT : (thanks to Tobi)
I needed to add the user_location
in login permissions and then, to find the location, I used :
let obj = result.objectForKey("location")
let location = obj.objectForKey("name") as! String
推荐答案
您需要确保用户访问令牌您正在使用的包含 user_hometown
权限:
You need to make sure that the User Access Token you're using contains the user_hometown
permission:
- https://developers.facebook.com/docs/facebook-login/permissions#reference-user_hometown
另外,请确保您真的想要 hometown
而不是用户的
位置
(当前城市)。后者将是 user_location
权限:
Also, make sure that you really want the hometown
and not the location
(current city) of the user. The latter would be the user_location
permission:
这篇关于iOS以快速,最新的FBSDK为用户的家乡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!