dimanche 19 avril 2015

Error: Domain "com.facebook.sdk" - code: 5

I keep getting an error when I am trying to get an individual's profile picture. I get the error com.facebook.sdk - code:5 and I'm not too sure why I am getting it. This is my code:



FBRequestConnection.startForMeWithCompletionHandler { (connection, user, error) -> Void in
//Get individual's profile picture. My error occurs on the NEXT line.
let url = NSURL(string: "http://ift.tt/1GaqSEG") //This is where my error occurs
let urlRequest = NSURLRequest(URL: url!)
//Asynchronous request to display image
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in

// Display the image
let image = UIImage(data: data)
self.profilePic.image = image

}
}


In the code above, the line that gives me issues is the let url = NSURL(...) line and it simply returns nil. I'm really puzzled by this error because when I looked up different solutions online, they said it was because my FBSession was not active. However, I had a statement, if FBSession.activeSession().isOpen right above this code and the code still failed on the let url = NSURL(...) line. Strange this is that this code seems to work sometimes and more recently it has been giving me a lot of issues. When I first implemented it, it was working fine. If it helps, I get 3 different errors saying com.facebook.sdk:ErrorInnerErrorKey, com.facebook.sdk:ErrorSessionKey, and com.facebook.HTTPStatusCode 200. Any help would be appreciated! Thanks.


EDIT: I also tried to add in FBSession.openActiveSessionWithAllowLoginUI(false) in the func applicationDidBecomeActive(application: UIApplication) method and it seems to fix things after the first run but on any runs after that it doesn't seem to work.


Aucun commentaire:

Enregistrer un commentaire