Facebook的FBSDKLoginManager / logInWithReadPermissions Swift示例不使用分析

最新的Facebook Swift文档在哪里? 我不能让FBlogin对话框出现。 对loginWithReadPermissions的调用永远不会返回?

import UIKit import FBSDKCoreKit import FBSDKLoginKit class ViewController: UIViewController {override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let loginManager = FBSDKLoginManager() loginManager.logInWithReadPermissions(["basic_info", "email", "user_likes"], fromViewController: self.parentViewController, handler: { (result, error) -> Void in if error != nil { print(FBSDKAccessToken.currentAccessToken()) } else if result.isCancelled { print("Cancelled") } else { print("LoggedIn") } }) } 

如果你从权限中排除“ user_likes ”,你的代码应该可以工作。 从脸书文档: 如果您的应用程序要求不只是public_profile电子邮件user_friends ,Facebook必须审查它,然后才能释放它。 详细了解审核stream程以及通过审核所需的内容。 https://developers.facebook.com/docs/facebook-login/permissions/v2.5#reference-user_likes

另一个问题可能是您没有正确设置您的项目中的FacebookSDK。 请参阅本教程: https : //developers.facebook.com/docs/ios/getting-started/

所以答案是用下面的FBSDKLoginButton

在viewController的类声明中

 import FBSDKCoreKit import FBSDKLoginKit class ViewController: UIViewController, FBSDKLoginButtonDelegate 

然后显示FBLoginbutton

  // Setup the FB Login/Logout Button FB will take care of the // verbiage based on the current access token let loginView : FBSDKLoginButton = FBSDKLoginButton() self.view.addSubview(loginView) loginView.center = self.view.center loginView.readPermissions = ["public_profile", "email", "user_friends"] loginView.delegate = self // If we have an access token, then let's display some info if (FBSDKAccessToken.currentAccessToken() != nil) { // Display current FB premissions print (FBSDKAccessToken.currentAccessToken().permissions) // Since we already logged in we can display the user datea and taggable friend data. self.showUserData() self.showFriendData() } 

显示用户信息

  func showUserData() { let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "id, name, gender, first_name, last_name, locale, email"]) graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in if ((error) != nil) { // Process error print("Error: \(error)") } else { let userName : NSString = result.valueForKey("name") as! NSString print("User Name is: \(userName)") if let userEmail : NSString = result.valueForKey("email") as? NSString { print("User Email is: \(userEmail)") } } }) } 

并显示标签的朋友

 func showFriendData() { let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/taggable_friends?limit=999", parameters: ["fields" : "name"]) graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in if ((error) != nil) { // Process error print("Error: \(error)") } else { if let friends : NSArray = result.valueForKey("data") as? NSArray{ var i = 1 for obj in friends { if let name = obj["name"] as? String { print("\(i) " + name) i++ } } } } }) }