ios - 没有得到 FBSDKtoken

标签 ios swift swift3

 - @IBAction func BtnFaceBookLogin(_ sender: Any)
       {
           let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
           fbLoginManager.logOut()
           fbLoginManager.logIn(withReadPermissions: ["public_profile", "email"], from: self) { (result, error) -> Void in
               if (error == nil){
                   let fbloginresult : FBSDKLoginManagerLoginResult = result!
                   if(fbloginresult.grantedPermissions.contains("email"))
                   {
                       self.getFBUserData()
                   }
               }
           }
       }

   func getFBUserData()
       {
           if((FBSDKAccessToken.current()) != nil)
           {
               FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large),
   email"]).start(completionHandler: { (connection, result, error) ->
   Void in
                   if (error == nil)
                   {
                       print(result!)

                       let socialID1:[String:AnyObject] = result as! [String : AnyObject]

                       let socialID = socialID1["id"] as! String

                       print(socialID)
                   }
                   else
                   {
                       print("Not Dismiss");
                   }
               })
           }
       }

我试过这段代码但没有得到任何回应,出现错误:

unexpectedly found nil while unwrapping an Optional value

我没有获得 FBSDKtoken。

最佳答案

let loginManager = FBSDKLoginManager()
        loginManager.logIn(withReadPermissions: ["user_about_me", "email" , "user_birthday","user_hometown"], from: self) { (loginResult, error) in
            if error != nil
            {

            }
            else
            {
                if loginResult?.grantedPermissions == nil
                {

                    return
                }


                if (loginResult?.grantedPermissions.contains("email"))!
                {
                    if (loginResult?.grantedPermissions.contains("user_birthday"))!
                    {
                        self.getFBUserData()
                    }

                }
                }}

    }
    func getFBUserData()
    {

        FBSDKGraphRequest.init(graphPath: "me?fields=id,name,email,first_name,last_name,cover,picture.type(large),gender,birthday,hometown", parameters: nil).start(completionHandler: { (connection , result , error ) in

            if(error == nil){



                DispatchQueue.main.async {
                    let dictionary = result as! NSDictionary

                    print(dictionary)
                    print("Name : \(dictionary.value(forKey: "name")!)")
                    print("FB ID : \(dictionary.value(forKey: "id")!)")


                }


            }else{

                self.showalert(strMessage: "Somthig Went Wrong..!")
            }
        })

    }

在 Swift-3 中试试这个

关于ios - 没有得到 FBSDKtoken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46523470/

相关文章:

ios - UITableView 分隔符样式缺失的行

ios - Touch ID - 如何进入密码屏幕? - swift

ios - 为多个 UIAlertController 分派(dispatch) asyncAfter

ios - GeoCoder 使用地址获取经度和纬度

ios - 使用音频队列 iOS api 将最后 30 秒的音频保存在文件中

ios - UITableView - 与表格 View 的交互消失了一切

ios - 为什么我看不到我的导航栏?

ios - Swift 不支持 SDK 'iPhoneSimulator9.3.sdk'?

uitableview - 使用swift3在tableview中搜索栏和部分

swift - 如何在 Swift 3 中修复我的自定义 UITextField 对象?