我已经将我的项目配置为使用Facebook SDK进行登录。我使用以下框架:
FBSDKShareKit
FBSDKLoginKit
FBSDKCoreKit
我在一个swift项目中使用这个,所以我已经添加了桥接头,将所有框架导入到头中,并在facebook开发者网站上注册项目后使用应用程序id正确配置属性列表。我还在AppDelegate方法中添加了必要的代码。
我的登录代码看起来像这样:
if(FBSDKAccessToken.currentAccessToken() != nil) {
returnUserData()
}
else{
let loginView = FBSDKLoginButton()
loginView.center = view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
view.addSubview(loginView)
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if ((error) != nil){
//Process error
println(error.localizedDescription)
}
else if result.isCancelled{
//Handle cancellations
}
else{
println(result.token.description)
//If you ask for multiple permissions you should check if
//specific permissions are missings.
if result.grantedPermissions.contains("email"){
returnUserData()
}
}
}
func returnUserData (){
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if ((error) != nil)
{
// Process error
println("Error: (error)")
}
else
{
let id : String = result.valueForKey("id") as! String
self.getUserProfileWithId(id)
let userName : NSString = result.valueForKey("name") as! String
}
}
}
https://developers.facebook.com/docs/facebook-login/permissions/v2.4
上面的链接是我引用的文档,我应该有权限。但是,当我运行请求时,我只从调用中接收"id"
和"name"
属性。
文档声明public_profile(默认)应该包含
*id
*name
*first_name
*last_name
*age_range
*link
*gender
*local
*timezone
*updated_time
*verified
然而,我从来没有收到这些属性,我已经确认我有这个代码的公共配置文件的授予权限。
if result.grantedPermissions.contains("public_profile"){
println("Permissions valid for profile")
}
我也改变了我的facebook帐户的设置,使它是可搜索的,没有任何限制,但这似乎也没有效果。我尝试了一个朋友的帐户,结果是相同的,只是id和名称字段从登录调用返回。关于如何获得完整的public_profile
信息的任何帮助将是awesome
对于v2.4,您必须请求想要在fields
参数列表中接收的每个字段:
- https://developers.facebook.com/docs/apps/changelog v2_4
为了尝试提高移动网络上的性能,v2.4中的node和edge要求您显式地请求GET请求所需的字段。例如,GET/v2.4/me/feed默认不再包含喜欢和评论,但是GET/v2.4/me/feed?Fields =comments,likes将返回数据。要了解更多详细信息,请参阅如何请求特定字段的文档。