2017-06-08 16 views
1

私はFacebookのログインの問題に苦しんでいます。昨日のFacebookのログインは正しく動作していますが、今日は私のアプリを起動すると動作しません。なぜか、なぜ突然動作していないのですか? Facebookのログインに関連するものは、すべてが設定されているコンソールを開発する あなたが考えているなら私を助けてください。私は既にキーチェーンの共有も有効にしています。 Facebookログインのためのenter image description hereIOS SDKでログインできません

コード

@IBAction func onClickFacebookLoginAction(_ sender: Any) { 

    var message = String() 
    if Reachability.isConnectedToNetwork() == true{ 

     let loginView:FBSDKLoginManager = FBSDKLoginManager() 
     loginView.loginBehavior = FBSDKLoginBehavior.web 
     loginView.logIn(withReadPermissions: ["email","public_profile","user_friends"], from: self, handler: { (result, error) in 
      if(error != nil){ 

       print("Error while try to login with facebook-\(error?.localizedDescription)") 
      }else if (result?.isCancelled)!{ 

       print("User cancel the facebook login") 
      }else{ 

       if result?.grantedPermissions != nil{ 
        if (result?.grantedPermissions .contains("email"))!{ 
         self.ShowProgressHUD() 
         self.fetchUserInfo() 
        }else{ 
         message = message.appending("Facebook email permission error") 
         self.showAlertMessage(message: message, title: "") 
        } 
       } 
      } 
     }) 
    } 
} 

func fetchUserInfo() -> Void { 

    if (FBSDKAccessToken.current() != nil) { 

     let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/me", parameters:["fields": "id, first_name, last_name, name, email, picture"]) 
     graphRequest.start(completionHandler: { (connection, result, error) in 

      if(error != nil){ 

       self.showAlertMessage(message: (error?.localizedDescription)!, title: "") 

      } 
      else 
      { 
       print("Result is:\(result)") 
       self.dictionary = result as! [String : AnyObject] 
       let name = self.dictionary["name"] as!String 
       let email = self.dictionary["email"] as! String 
       let token = FBSDKAccessToken.current().tokenString 

       print("name is -\(name)") 
       print("email is -\(email)") 
       print("token is -\(token)") 


       DispatchQueue.main.async { 

        let SelectionViewObj = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController 
        self.navigationController?.pushViewController(SelectionViewObj, animated: true) 
       } 
      } 
     }) 
    } 
} 
+0

'/' graphPathパラメータ値の前に 'graphPathがある理由:「/私」' –

+0

@PraveenKumarは、私はちょうどいくつかのチュートリアルと同じことをやってチュートリアルに従ってください。 –

+0

スラッシュを削除して試してみてください。 https://developers.facebook.com/docs/ios/graphの詳細を確認してください。https://stackoverflow.com/questions/31383578/ios-facebooksdk-get-user-full-details –

答えて

0

これは私がFacebookでログインするために使用する方法である、

@IBAction func act_loginFB(_ sender: UIButton) { 
    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() 
    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){ 
       //everything works print the user data 
       print(result) 
       let data: [String:AnyObject] = (result as? [String : AnyObject])! 
       print(data) 
       let email: String = data["email"]! as! String 
       print(email) 
      } 
     }) 
    } 
} 

は、あなたが情報に正しいFacebookAppIDFacebookDisplayNameを追加しました確認してください。 plist

+0

私はWebとしてログイン動作を開くにはSafariブラウザで開くしたくない、ブラウザで私のコードでも正しく動作している –

+0

@Sanjeetverma addこの 'fbLoginManager.loginBehavior = FBSDKLoginBehavior.web'はこの行の後に' let fbLoginManager:FBSDKLoginManager = FBSDKLoginManager() ' –

+0

私のコードでも使用しました。最初に –

0

これは私が認証に使用しているコードですチャームのように働くfacebook.itsを誘致してください。ちょうどこれを点検するか置き換えてください。

self.fbLoginManager = FBSDKLoginManager.init() 
fbLoginManager.loginBehavior = FBSDKLoginBehavior.web 
self.fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) -> Void in 
    if (error == nil) { 
     let fbloginresult : FBSDKLoginManagerLoginResult = result! 
     if fbloginresult.grantedPermissions != nil && fbloginresult.grantedPermissions.contains("email") { 
      if((FBSDKAccessToken.current()) != nil){ 
       FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id, first_name, last_name, email, gender, birthday, location"]).start(completionHandler: { (connection, result, error) -> Void in 
        if error != nil { 
         print(error?.localizedDescription ?? "error in facebook login...!") 
         return 
        } 
        if let dict = result as? NSDictionary { 
         print("facebook login result --->\n\(dict)") 
         guard let id = dict["id"] else { 
          print("Ooops... id = nil") 
          return 
         } 
         // let firstName: String = dict["first_name"] as? String ?? "" 
         // let lastName : String = dict["last_name"] as? String ?? "" 
         // let email : String = dict["email"] as? String ?? "" 

         self.fbLoginManager.logOut() 
        } 
       }) 
      } 
     } else { 
      print("facebook ---> login canceled") 
     } 
    } else { 
     print(error?.localizedDescription ?? "facebook login has error") 
    } 
} 
+0

試してみると同じエラーが発生しますあなたの答えを –

+0

私はfbの開発者のコ​​ンソールからプロジェクトを削除&新しいプロジェクトを作成し、これを試してみると思う.... –

+0

私のアプリケーションはApp Storeに公開されていますが、今ではいくつかの機能を追加しています。削除した場合、Facebookのログイン作業がライブで停止している可能性もあります –

関連する問題