dimanche 19 avril 2015

Facebook Completion Handler returning null?

I am using the Facebook API and I am using the FBRequestConnection.startForMeWithCompletionHandler method to get a user's profile picture. This was working fine for me until recently where suddenly my application constantly fails because the id parameter returns null. I looked up the documentation and it shows the following as the parameters: [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)


This is my code so far:



FBRequestConnection.startForMeWithCompletionHandler { (connection, user, error) -> Void in
//Get individual's profile picture
let url = NSURL(string: "http://ift.tt/1GaqSEG")
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)
if(image != nil){
completion(result: true, image: self.profilePic.image)
}
}

}


Oddly enough, the user parameter in the function always returns nil and I'm not sure why. I have looked at multiple links on stack overflow and most say that either my session is inactive or I am logged out, but I have tested both and my session is indeed active. Moreover, I looked in my errors array and I got a HTTP 200 Status Code meaning that my connection works. I get two other errors, com.facebook.sdk:ErrorInnerErrorKey and com.facebook.sdk:ErrorSessionKey but upon looking into these errors, I can't find anything about them. Any help would be appreciated. Thanks!


Aucun commentaire:

Enregistrer un commentaire