The operation couldn’t be completed. (com.facebook.sdk.login error 301.)

2.9k views Asked by At

When I clicked on loginWithFacebook button, I'm getting this error,

The operation couldn’t be completed. (com.facebook.sdk.login error 301.)

There is no much information regarding what is this error code 301 means. Any suggestions or info regrading this greatly appreciated.

Note: This one is not getting in iPhone, specifically when I run on iPAD. Don't know why.

2

There are 2 answers

1
Sivajee Battina On BEST ANSWER

I got to know what causes this error. Even though it's funny error, it's good to know about this. The device which I'm running on has no browser to use. So facebook wants to open url in browser and it's failed to do so. That gave me error with facebookSDK.Login.Error.code: 301.

You can resolve this by setting FBSDKLoginManager.loginBehaviour to required behaviour(Browser, Web or App).

0
seggy On

This is my code working properly

Please import first

  import FacebookLogin
  import FBSDKLoginKit 

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {

if(FBSDKAccessToken.current() != nil)
    {
        //print permissions, such as public_profile
        print(FBSDKAccessToken.current().permissions)
        let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "id, name, email"])
        let connection = FBSDKGraphRequestConnection()

        connection.add(graphRequest, completionHandler: { (connection, result, error) -> Void in

            let data = result as! [String : AnyObject]

            self.lbluser.text = data["name"] as? String

            let FBid = data["id"] as? String
            self.lblEmail.text = data["email"] as? String

            let url = NSURL(string: "https://graph.facebook.com/\(FBid!)/picture?type=large&return_ssl_resources=1")
            self.imageView.image = UIImage(data: NSData(contentsOf: url! as URL)! as Data)
        })
        connection.start()
    }
}